aws-amplify / aws-amplify/amplify-cli

Amplify export to cdk is missing templateUrl property for one of nested stack

Open
#13,297 2 comments 0 reactions 0 assignees View on GitHub
auth bug export p3
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### How did you install the Amplify CLI?

npm

### If applicable, what version of Node.js are you using?

_No response_

### Amplify CLI Version

12.2.3

### What operating system are you using?

Mac

### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

There's a work around by manually updating the generated root-stack-template.json. Adding
"TemplateURL": "https://s3.amazonaws.com/amplify-verifimeportalweb-dev-14927-deployment/amplify-cfn-templates/auth/auth-trigger-cloudformation-template.json ",
to AuthTriggerCustomLambdaStack.Properties.

### Describe the bug

Exported backend to CDK fails to build when Lambda auth triggers are added.

### Expected behavior

this should not require manual intervention and should function normally just like it would without the custom triggers being added

### Reproduction steps

```sh
$ mkdir cdk-app
$ cd cdk-app
$ cdk init app --language typescript
$ cd ..
$ mkdir amplify-cdk
$ cd amplify-cdk
$ amplify init
$ amplify add auth >> add auth with a custom lambda trigger
$ amplify push --y
$ amplify export --out ../cdk-app/lib/
$ cd ../cdk-app
$ npm i @aws-amplify/cdk-exported-backend
$ npm i lodash
- Added below snippet to cdk-app/bin/cdk-app.ts
const amplifyStack = new AmplifyExportedBackend(app, "AmplifyExportedBackend", {
path: path.resolve(__dirname, "../lib", "amplify-export-amplifycdk"),
amplifyEnvironment: "dev",
});
$ cdk ls >> errors out due to missing templateUrl property
```

### Project Identifier

_No response_

### Log output

```
/Users/charlesjiang/Work/verifyme-portal-web/node_modules/aws-cdk-lib/core/lib/runtime.js:4
^
Error: VerifimePortalWebAmplifyExportedBackend-amplify-backend-stack/AmplifyCfnInclude/AuthTriggerCustomLambdaStack [AWS::CloudFormation::Stack] is missing required property: templateUrl
at Object.requireProperty (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/aws-cdk-lib/core/lib/runtime.js:4:2814)
at new CfnStack (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/aws-cdk-lib/core/lib/cloudformation.generated.js:1:51748)
at Function._fromCloudFormation (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/aws-cdk-lib/core/lib/cloudformation.generated.js:1:51230)
at CfnInclude.getOrCreateResource (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:12982)
at new CfnInclude (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/aws-cdk-lib/cloudformation-include/lib/cfn-include.js:1:2011)
at new AmplifyExportedBackend (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/@aws-amplify/cdk-exported-backend/src/export-backend.ts:69:21)
at Object. (/Users/charlesjiang/Work/verifyme-portal-web/cdk/verifime-cognito/bin/verifime-cognito.ts:15:1)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module.m._compile (/Users/charlesjiang/Work/verifyme-portal-web/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)

Subprocess exited with error 1

```

### Additional information

worked around by updating the generated root-stack-template.json. Adding
"TemplateURL": "https://s3.amazonaws.com/amplify-verifimeportalweb-dev-14927-deployment/amplify-cfn-templates/auth/auth-trigger-cloudformation-template.json ",
to AuthTriggerCustomLambdaStack.Properties.

However, this should not require manual intervention and should function normally just like it would without the custom triggers being added

### Before submitting, please confirm:

- [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.

Contributor guide

Open the contributing guide

Research direction

Start with the generated root-stack-template.json and the cdk-exported-backend entry point shown at @aws-amplify/cdk-exported-backend/src/export-backend.ts:69. Reproduce the issue with the listed amplify export and cdk ls commands, then trace why AuthTriggerCustomLambdaStack lacks TemplateURL. Done means the exported backend builds without manually editing the generated template.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cli, cloud, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.