amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Storage update to add Trigger

Open foxfl opened this issue 6 years ago • 15 comments

Describe the bug When trying to add a Lambda Trigger to the Storage category to an existing Bucket, generated through the CLI, the cloudformation update fails with:

Unable to validate the following destination configurations (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; ...)

Amplify CLI Version 4.12.0

To Reproduce

amplify update storage
? Please select from one of the below mentioned services: Content (Images, audio, video, etc.)
? Who should have access: Auth and guest users
? What kind of access do you want for Authenticated users? (Press <space> to select, <a> to toggle all, <i> to invert selection)read
? What kind of access do you want for Guest users? (Press <space> to select, <a> to toggle all, <i> to invert selection)read
? Do you want to add a Lambda Trigger for your S3 Bucket? Yes
? Select from the following options Create a new function
Successfully added resource S3Trigger425e293d locally
? Do you want to edit the local S3Trigger425e293d lambda function now? No
Successfully updated resource
amplify push

| Category | Resource name             | Operation | Provider plugin   |
| -------- | ------------------------- | --------- | ----------------- |
| Function | S3Trigger425e293d         | Create    | awscloudformation |
| Storage  | RenToStorage              | Update    | awscloudformation |

This results in the following error:

UPDATE_FAILED               S3Bucket                                                   AWS::S3::Bucket            Tue Jan 14 2020 11:37:53 GMT+0100 (GMT+01:00) Unable to validate the following destination configurations (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: 067DFD7D99E0C783; S3 Extended Request ID: eW2csxhTfjUd3Rz5+AXeeObnAtpksDBX3uKyHq7qg1Dyj2kqnlZsfu/m93U/vQs8W96P5fy1M04=)
UPDATE_IN_PROGRESS          S3Bucket                                                   AWS::S3::Bucket            Tue Jan 14 2020 11:37:52 GMT+0100 (GMT+01:00)




UPDATE_FAILED storageRenToStorage AWS::CloudFormation::Stack Tue Jan 14 2020 11:37:55 GMT+0100 (GMT+01:00) Embedded stack arn:aws:cloudformation:eu-central-1:124149422162:stack/rento-dev-20190818200122-storageRenToStorage-1TK3A4S344829/fad0f590-ca7a-11e9-a2e9-0a43c0b04aee was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: The following resource(s) failed to update: [S3Bucket].
- Updating resources in the cloud. This may take a few minutes...

Expected behavior The Lambda Trigger is created and added to the S3 Bucket

Desktop (please complete the following information):

  • OS: [Windows]
  • Node Version: v12.14.1

foxfl avatar Jan 14 '20 10:01 foxfl

Can you try pushing again and check if you see the same error?

kaustavghosh06 avatar Jan 14 '20 19:01 kaustavghosh06

Which region are you deploying to? I'm currently on v4.12.0 and here's my terminal output log with the same flow as yours. Please let me know if I'm doing anything different.

f45c89966b0d:oliand kaustavg$ amplify update storage
? Please select from one of the below mentioned services: Content (Images, audio, video, etc.)
? Who should have access: Auth users only
? What kind of access do you want for Authenticated users? (Press <space> to select, <a> to toggle all, <i> to invert selection)create/update
? Do you want to add a Lambda Trigger for your S3 Bucket? Yes
? Select from the following options Create a new function
Successfully added resource S3Triggereba7feb9 locally
? Do you want to edit the local S3Triggereba7feb9 lambda function now? No
Successfully updated resource
f45c89966b0d:oliand kaustavg$ amplify push
✔ Successfully pulled backend environment dev from the cloud.

Current Environment: dev

| Category | Resource name      | Operation | Provider plugin   |
| -------- | ------------------ | --------- | ----------------- |
| Function | S3Triggereba7feb9  | Create    | awscloudformation |
| Storage  | s36e7cff29         | Update    | awscloudformation |
| Auth     | cultureapp7df34888 | No Change | awscloudformation |
? Are you sure you want to continue? Yes
⠴ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE    authcultureapp7df34888         AWS::CloudFormation::Stack Tue Jan 14 2020 11:40:27 GMT-0800 (Pacific Standard Time)                            
CREATE_IN_PROGRESS functionS3Triggereba7feb9      AWS::CloudFormation::Stack Tue Jan 14 2020 11:40:26 GMT-0800 (Pacific Standard Time) Resource creation Initiated
UPDATE_IN_PROGRESS authcultureapp7df34888         AWS::CloudFormation::Stack Tue Jan 14 2020 11:40:26 GMT-0800 (Pacific Standard Time)                            
CREATE_IN_PROGRESS functionS3Triggereba7feb9      AWS::CloudFormation::Stack Tue Jan 14 2020 11:40:25 GMT-0800 (Pacific Standard Time)                            
UPDATE_IN_PROGRESS amplify-culture-app-dev-105505 AWS::CloudFormation::Stack Tue Jan 14 2020 11:40:22 GMT-0800 (Pacific Standard Time) User Initiated             
⠼ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS LambdaExecutionRole                                                    AWS::IAM::Role             Tue Jan 14 2020 11:40:29 GMT-0800 (Pacific Standard Time) Resource creation Initiated
CREATE_IN_PROGRESS LambdaExecutionRole                                                    AWS::IAM::Role             Tue Jan 14 2020 11:40:29 GMT-0800 (Pacific Standard Time)                            
CREATE_IN_PROGRESS amplify-culture-app-dev-105505-functionS3Triggereba7feb9-1FNAJPKDJOVAL AWS::CloudFormation::Stack Tue Jan 14 2020 11:40:26 GMT-0800 (Pacific Standard Time) User Initiated             
⠹ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE LambdaExecutionRole AWS::IAM::Role Tue Jan 14 2020 11:40:45 GMT-0800 (Pacific Standard Time) 
⠋ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS LambdaFunction AWS::Lambda::Function Tue Jan 14 2020 11:40:47 GMT-0800 (Pacific Standard Time) 
⠙ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE    LambdaFunction AWS::Lambda::Function Tue Jan 14 2020 11:40:48 GMT-0800 (Pacific Standard Time)                            
CREATE_IN_PROGRESS LambdaFunction AWS::Lambda::Function Tue Jan 14 2020 11:40:48 GMT-0800 (Pacific Standard Time) Resource creation Initiated
⠏ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS lambdaexecutionpolicy AWS::IAM::Policy Tue Jan 14 2020 11:40:50 GMT-0800 (Pacific Standard Time) 
⠸ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS lambdaexecutionpolicy AWS::IAM::Policy Tue Jan 14 2020 11:40:51 GMT-0800 (Pacific Standard Time) Resource creation Initiated
⠏ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE lambdaexecutionpolicy AWS::IAM::Policy Tue Jan 14 2020 11:41:05 GMT-0800 (Pacific Standard Time) 
⠙ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE amplify-culture-app-dev-105505-functionS3Triggereba7feb9-1FNAJPKDJOVAL AWS::CloudFormation::Stack Tue Jan 14 2020 11:41:06 GMT-0800 (Pacific Standard Time) 
⠼ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE functionS3Triggereba7feb9 AWS::CloudFormation::Stack Tue Jan 14 2020 11:41:13 GMT-0800 (Pacific Standard Time) 
⠋ Updating resources in the cloud. This may take a few minutes...

UPDATE_IN_PROGRESS storages36e7cff29 AWS::CloudFormation::Stack Tue Jan 14 2020 11:41:15 GMT-0800 (Pacific Standard Time) 
⠋ Updating resources in the cloud. This may take a few minutes...

UPDATE_IN_PROGRESS amplify-culture-app-dev-105505-storages36e7cff29-14N42JMR8GQI0 AWS::CloudFormation::Stack Tue Jan 14 2020 11:41:15 GMT-0800 (Pacific Standard Time) User Initiated
⠧ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS TriggerPermissions AWS::Lambda::Permission Tue Jan 14 2020 11:41:21 GMT-0800 (Pacific Standard Time) Resource creation Initiated
CREATE_IN_PROGRESS TriggerPermissions AWS::Lambda::Permission Tue Jan 14 2020 11:41:20 GMT-0800 (Pacific Standard Time)                            
⠧ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE TriggerPermissions AWS::Lambda::Permission Tue Jan 14 2020 11:41:31 GMT-0800 (Pacific Standard Time) 
⠙ Updating resources in the cloud. This may take a few minutes...

UPDATE_IN_PROGRESS S3Bucket AWS::S3::Bucket Tue Jan 14 2020 11:41:34 GMT-0800 (Pacific Standard Time) 
⠦ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE S3Bucket AWS::S3::Bucket Tue Jan 14 2020 11:41:55 GMT-0800 (Pacific Standard Time) 
⠙ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS S3TriggerBucketPolicy AWS::IAM::Policy Tue Jan 14 2020 11:41:58 GMT-0800 (Pacific Standard Time) 
UPDATE_IN_PROGRESS S3AuthPublicPolicy    AWS::IAM::Policy Tue Jan 14 2020 11:41:58 GMT-0800 (Pacific Standard Time) 
UPDATE_IN_PROGRESS S3AuthUploadPolicy    AWS::IAM::Policy Tue Jan 14 2020 11:41:58 GMT-0800 (Pacific Standard Time) 
UPDATE_IN_PROGRESS S3AuthProtectedPolicy AWS::IAM::Policy Tue Jan 14 2020 11:41:58 GMT-0800 (Pacific Standard Time) 
UPDATE_IN_PROGRESS S3AuthPrivatePolicy   AWS::IAM::Policy Tue Jan 14 2020 11:41:58 GMT-0800 (Pacific Standard Time) 
⠧ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS S3TriggerBucketPolicy AWS::IAM::Policy Tue Jan 14 2020 11:41:59 GMT-0800 (Pacific Standard Time) Resource creation Initiated
⠧ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE S3AuthPublicPolicy    AWS::IAM::Policy Tue Jan 14 2020 11:42:14 GMT-0800 (Pacific Standard Time) 
CREATE_COMPLETE S3TriggerBucketPolicy AWS::IAM::Policy Tue Jan 14 2020 11:42:14 GMT-0800 (Pacific Standard Time) 
UPDATE_COMPLETE S3AuthUploadPolicy    AWS::IAM::Policy Tue Jan 14 2020 11:42:13 GMT-0800 (Pacific Standard Time) 
UPDATE_COMPLETE S3AuthProtectedPolicy AWS::IAM::Policy Tue Jan 14 2020 11:42:13 GMT-0800 (Pacific Standard Time) 
UPDATE_COMPLETE S3AuthPrivatePolicy   AWS::IAM::Policy Tue Jan 14 2020 11:42:13 GMT-0800 (Pacific Standard Time) 
⠧ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE storages36e7cff29 AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:17 GMT-0800 (Pacific Standard Time) 
⠴ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE                     authcultureapp7df34888         AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:20 GMT-0800 (Pacific Standard Time) 
UPDATE_IN_PROGRESS                  authcultureapp7df34888         AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:20 GMT-0800 (Pacific Standard Time) 
UPDATE_IN_PROGRESS                  storages36e7cff29              AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:20 GMT-0800 (Pacific Standard Time) 
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS amplify-culture-app-dev-105505 AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:19 GMT-0800 (Pacific Standard Time) 
⠧ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE                     amplify-culture-app-dev-105505-storages36e7cff29-14N42JMR8GQI0 AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:21 GMT-0800 (Pacific Standard Time) 
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS amplify-culture-app-dev-105505-storages36e7cff29-14N42JMR8GQI0 AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:16 GMT-0800 (Pacific Standard Time) 
⠋ Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE amplify-culture-app-dev-105505 AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:31 GMT-0800 (Pacific Standard Time) 
UPDATE_COMPLETE storages36e7cff29              AWS::CloudFormation::Stack Tue Jan 14 2020 11:42:31 GMT-0800 (Pacific Standard Time) 
✔ All resources are updated in the cloud


kaustavghosh06 avatar Jan 14 '20 19:01 kaustavghosh06

Hi @kaustavghosh06,

I'm currently deploying to the region eu-central-1. Trying to push again did not work for me, still seeing the same issues.

I may have to say that i recently updated the CLI and then tried to add the Trigger. The bucket was created with an older version of the CLI (I think it was version 4.6.0). Maybe this issue is caused by the version difference?

foxfl avatar Jan 15 '20 09:01 foxfl

I'm going to create a new Bucket and add a trigger with the current version of the CLI and let you know if the error still occurs

foxfl avatar Jan 15 '20 09:01 foxfl

So, creating a new Project, adding Auth and Storage, then updating Storage to add a trigger actually worked.

I also added a additional function which has access to the bucket (I also do have one in my original project) but I could not reproduce the error.

It seems there is somehow a difference between the generated CloudFormation template form version 4.6.0 and 4.12.0. From my understanding Unable to validate the following destination configurations indicates that there seems to be something missing or wrong with the CloudFormation template

foxfl avatar Jan 15 '20 09:01 foxfl

@foxfl Yeah, it's super weird. I tried to create bucket using version 4.1.0 and did the update flow using 4.12.0 and wasn't able to reproduce. I'll re-open this issue if someone else is also seeing the same error and comments on this thread.

kaustavghosh06 avatar Jan 16 '20 19:01 kaustavghosh06

Having the same issue. After running amplify update storage and amplify push I get the same error on ap-southeast-1

ok-martin avatar Jan 20 '20 05:01 ok-martin

Facing the same issue!

hnprashanth avatar Feb 10 '20 09:02 hnprashanth

I've got the same problem.

dushek avatar Feb 12 '20 11:02 dushek

There was a problem with the name generated by my previous stack for AWS:S3:Bucket, I've just added following code to solve the problem: "Properties": { "BucketName": { "Fn::If": [ "ShouldNotCreateEnvResources", { "Ref": "bucketName" }, { "Fn::Join": [ "", [ { "Ref": "bucketName" }, { "Fn::Select": [ 3, { "Fn::Split": [ "-", { "Ref": "AWS::StackName" } ] } ] }, "-", { "Ref": "env" } ] ] } ] },

dushek avatar Feb 12 '20 14:02 dushek

Dealing with the same issue @dushek Can you elaborate on your fix?

julescsv avatar Feb 28 '20 23:02 julescsv

I was having the same issue, however I can confirm that @dushek 's fix seems to have done the trick, thanks!

To give a little more detail, I simply added the above code snippet (there were a couple of extraneous brackets) to s3-cloudformation-template.json under the storage category. I also deleted the existing BucketName property.

"BucketName": { "Fn::If": [ "ShouldNotCreateEnvResources", { "Ref": "bucketName" }, { "Fn::Join": [ "", [ { "Ref": "bucketName" }, { "Fn::Select": [ 3, { "Fn::Split": [ "-", { "Ref": "AWS::StackName" } ] } ] }, "-", { "Ref": "env" } ] ] } ] },

Hope this helps someone, thanks @dushek

samputer avatar Jul 05 '20 11:07 samputer

There was a problem with the name generated by my previous stack for AWS:S3:Bucket, I've just added following code to solve the problem: "Properties": { "BucketName": { "Fn::If": [ "ShouldNotCreateEnvResources", { "Ref": "bucketName" }, { "Fn::Join": [ "", [ { "Ref": "bucketName" }, { "Fn::Select": [ 3, { "Fn::Split": [ "-", { "Ref": "AWS::StackName" } ] } ] }, "-", { "Ref": "env" } ] ] } ] },

This will create a new bucket with a different name, there is no problem when adding trigger to a new bucket. The problem occurs when you try to update an existing S3 bucket. I don't believe creating a new bucket is a 'real' solution for it especially when it is already in use.

zohaib-amir-tkxel avatar Jul 28 '20 23:07 zohaib-amir-tkxel

There was a problem with the name generated by my previous stack for AWS:S3:Bucket, I've just added following code to solve the problem: "Properties": { "BucketName": { "Fn::If": [ "ShouldNotCreateEnvResources", { "Ref": "bucketName" }, { "Fn::Join": [ "", [ { "Ref": "bucketName" }, { "Fn::Select": [ 3, { "Fn::Split": [ "-", { "Ref": "AWS::StackName" } ] } ] }, "-", { "Ref": "env" } ] ] } ] },

I used this code also and it fixed the push error, but changed the current bucket name and messed up the entire project. What this code actually do?

tombaumg avatar Nov 12 '20 07:11 tombaumg

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 14:05 github-actions[bot]