Amplify Push overwrites json file
Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
14.18.3
Amplify CLI Version
7.6.24
What operating system are you using?
Amazon Linux
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
I am trying to create S3 Object Create to trigger a lambda. So I am doing
amplify add storage select other files
Because the options are limited from CLI, I need to update CFN file to I need to customize the S3 trigger to add filter, updates CORS and to remove s3 delete trigger.
Hence I am editing the file: ./amplify/backend/storage/s3BucketTest/build/s3BucketTest-cloudformation-template.json
When I run amplify push the file immediately gets overwritten and the changes to json are lost.
Amplify Categories
storage
Amplify Commands
push
Describe the bug
I am trying to create S3 Object Create to trigger a lambda. So I am doing
amplify add storage select other files
Because the options are limited from CLI, I need to update CFN file to I need to customize the S3 trigger to add filter, updates CORS and to remove s3 delete trigger.
Hence I am editing the file: ./amplify/backend/storage/s3BucketTest/build/s3BucketTest-cloudformation-template.json
When I run amplify push the file immediately gets overwritten and the changes to json are lost.
Expected behavior
The updated json to be deployed to cloud
Reproduction steps
Edit ./amplify/backend/storage/Table1/build/Table1-cloudformation-template.json amplify push
GraphQL schema(s)
No response
Log output
No response
Additional information
No response
Hey @gouthasnm :wave: thanks for raising this, and this sounds like a great use case for storage overrides! https://docs.amplify.aws/cli/storage/override/ With this we can run amplify override storage which will allow us to override the generated CloudFormation template, persisting across pushes and environments.
It is important to note the resources' build/ directory will be overwritten upon amplify build which is run on amplify push
Thanks ... I was looking for a way to do it without override. However, I ended up using override. Below is what I used:
import { AmplifyS3ResourceTemplate } from '@aws-amplify/cli-extensibility-helper';
import * as s3 from '@aws-cdk/aws-s3';
export function override(resources: AmplifyS3ResourceTemplate) {
const currentTriggerSettings = resources.s3Bucket.notificationConfiguration as s3.CfnBucket.NotificationConfigurationProperty;
const farn = currentTriggerSettings.lambdaConfigurations[0].function;
const newTriggerConfig = {
event: "s3:ObjectCreated:*",
filter: {
s3Key: {
rules: [
{
name: "prefix",
value: "public/app/etl-input-data/"
}
]
}
},
function: farn
} as s3.CfnBucket.LambdaConfigurationProperty;
const notificationConfigurationProperty: s3.CfnBucket.NotificationConfigurationProperty = {
lambdaConfigurations: [newTriggerConfig]
};
resources.s3Bucket.notificationConfiguration = notificationConfigurationProperty;
const currentCORSSettings = resources.s3Bucket.corsConfiguration as s3.CfnBucket.CorsConfigurationProperty;
const sarn = currentCORSSettings.corsRules[0].s3Bucket;
const newCORSConfig = {
allowedHeaders: ["*"],
allowedMethods: ["GET", "HEAD", "POST", "PUT"],
allowedOrigins: ["https://web1.com",
"https://web2.com"],
exposedHeaders: [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2",
"ETag"
],
id: "S3CORSRuleId1",
maxAge: 3000
} as s3.CfnBucket.CorsRuleProperty;
const corsConfigurationProperty: s3.CfnBucket.CorsConfigurationProperty = {
corsRules: [newCORSConfig]
};
resources.s3Bucket.corsConfiguration = corsConfigurationProperty;
}
Hey @gouthasnm glad to hear that worked for you! And apologies for the delay. Based on your latest update I will close this issue for now, however if you are still experiencing this issue please reply back to this thread and we can re-open to investigate further 🙂