Describe the bug
In CDK 2.202.0, PR #31771 was introduced, which added support for appRoot in custom response headers for Amplify. This PR caused issues in our application for some uses of the amplify.App construct. Specifically, the issue appeared whenever custom_response_headers was an empty list.
Regression Issue
Last Known Working CDK Library Version
2.201.0
Expected Behavior
Run cdk synth without errors
Current Behavior
Running cdk synth fails with the following error.
jsii.errors.JavaScriptError:
TypeError: Cannot read properties of undefined (reading 'appRoot')
at renderCustomResponseHeaders (REDACTED\node_modules\@aws-cdk\aws-amplify-alpha\lib\app.js:269:41)
at new App (REDACTED\node_modules\@aws-cdk\aws-amplify-alpha\lib\app.js:103:58)
at new App (REDACTED\node_modules\aws-cdk-lib\core\lib\prop-injectable.js:1:488)
at Kernel._Kernel_create (REDACTED\Local\Temp\tmpzcf1ob0l\lib\program.js:548:25)
at Kernel.create (REDACTED\Local\Temp\tmpzcf1ob0l\lib\program.js:218:93)
at KernelHost.processRequest (REDACTED\Local\Temp\tmpzcf1ob0l\lib\program.js:15479:36)
at KernelHost.run (REDACTED\Local\Temp\tmpzcf1ob0l\lib\program.js:15439:22)
at Immediate._onImmediate (REDACTED\Local\Temp\tmpzcf1ob0l\lib\program.js:15440:45)
at process.processImmediate (node:internal/timers:485:21)
Reproduction Steps
My example is based on Python, but given how simple it is, it should not be a problem to reproduce this in other languages.
app = amplify.App(
self, 'App',
custom_response_headers=[],
)
Possible Solution
#31771 Added (among other lines) the line
const hasAppRoot = customHeaders[0].appRoot !== undefined; link.
My guess is that taking index 0 of an empty list is what is causing the error. In this case a possible solution would be to add a simple check that the list has more than 0 entries.
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.202.0
AWS CDK CLI version
2.1029.4 (build 09c0061)
Node.js Version
v22.20.0
OS
Windows 11
Language
Python
Language Version
No response
Other information
No response
Describe the bug
In CDK 2.202.0, PR #31771 was introduced, which added support for
appRootin custom response headers for Amplify. This PR caused issues in our application for some uses of theamplify.Appconstruct. Specifically, the issue appeared whenevercustom_response_headerswas an empty list.Regression Issue
Last Known Working CDK Library Version
2.201.0
Expected Behavior
Run
cdk synthwithout errorsCurrent Behavior
Running
cdk synthfails with the following error.Reproduction Steps
My example is based on Python, but given how simple it is, it should not be a problem to reproduce this in other languages.
Possible Solution
#31771 Added (among other lines) the line
const hasAppRoot = customHeaders[0].appRoot !== undefined;link.My guess is that taking index 0 of an empty list is what is causing the error. In this case a possible solution would be to add a simple check that the list has more than 0 entries.
Additional Information/Context
No response
AWS CDK Library version (aws-cdk-lib)
2.202.0
AWS CDK CLI version
2.1029.4 (build 09c0061)
Node.js Version
v22.20.0
OS
Windows 11
Language
Python
Language Version
No response
Other information
No response