aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.62k stars 3.91k forks source link

(amplify-alpha): Removing `customResponseHeaders` property does not remove the headers from the app #31783

Open georeeve opened 1 week ago

georeeve commented 1 week ago

Describe the bug

Creating an app with the customResponseHeaders property, and then removing the property does not remove the custom headers from the app.

Regression Issue

Last Known Working CDK Version

No response

Expected Behavior

Removing the customResponseHeaders property from the App construct should delete it from the Amplify app in the dashboard.

Current Behavior

The custom headers stay in their previous configuration.

Reproduction Steps

Create an example Amplify app with the customResponseHeaders property:

new amplify.App(this, 'App', {
  customResponseHeaders: [
    {
      pattern: '**',
      headers: {
        Test: 'test',
      },
    },
  ],
});

Then remove the customResponseHeaders property, observe that the headers are still in the Amplify dashboard.

Possible Solution

Omitting CustomHeaders in CloudFormation does not remove the headers from the app, instead we could explicitly set it to an empty string if the customResponseHeaders property is not provided, similar to how we currently handle the basicAuth property.

Additional Information/Context

No response

CDK CLI Version

2.162.1 (build 10aa526)

Framework Version

2.162.1-alpha.0

Node.js Version

v22.9.0

OS

macOS 14.7 (23H124)

Language

TypeScript

Language Version

TypeScript 5.6.3

Other information

No response

georeeve commented 1 week ago

I'm happy to submit a PR with the proposed solution, if that's what we want to do.

khushail commented 2 days ago

Hi @georeeve , thanks for reaching out.

I tried to repro the scenario by following the shared instructions and code. The app successfully deployed with custom headers initially but when the customResourceHeaders were removed, although I see the cdk diff result -

Screenshot 2024-10-21 at 2 56 23 PM

the deployed template also has the change -


"amplifyapp996AC4E0": {
      "Type": "AWS::Amplify::App",
      "Properties": {
        "BasicAuthConfig": {
          "EnableBasicAuth": false
        },
        "EnableBranchAutoDeletion": true,
        "IAMServiceRole": {
          "Fn::GetAtt": [
            "amplifyappRole19C50DA6",
            "Arn"
          ]
        },
        "Name": "amplifyapp",
        "Platform": "WEB"
      },
      "Metadata": {
        "aws:cdk:path": "AmplifyalphaStack/amplifyapp/Resource"
      }
    },

but the change is not propagated to Amplify app -

Screenshot 2024-10-21 at 3 01 37 PM

Checking the clooudformation docs, this field does not have any defaults -

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amplify-app.html#cfn-amplify-app-customheaders

As per the diff result, During deployment, cloudformation should update the App's customResponseheader and delete it. So this definitely seems to be a bug.

However passing an empty array did the trick for me -


    const amplifyapp = new amplify.App(this, 'amplifyapp', {
      customResponseHeaders: [],
      autoBranchDeletion: true, // Automatically disconnect a branch when you delete a branch from your repository
    }); 

Result of cdk diff -

Screenshot 2024-10-21 at 3 27 31 PM

Amplify app updated with empty customResponseHeader -

Screenshot 2024-10-21 at 3 28 47 PM

Please feel free to submit a PR. Team would be happy to review it.

khushail commented 2 days ago

I would be marking this issue as P3 as workaround exists , and contributions are welcome in this regard.