aws-amplify / aws-amplify/amplify-cli
Amplify cdk-stack output missing dependencies which are generated during cdk synth
- 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?
v16.20.0
### Amplify CLI Version
12.0.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.
No manual changes made
### Describe the bug
The way [amplify builds a cdk stack](https://github.com/aws-amplify/amplify-cli/blob/dev/packages/amplify-category-custom/src/utils/build-custom-resources.ts#L107-L116) and then [generates cfn](https://github.com/aws-amplify/amplify-cli/blob/dev/packages/amplify-category-custom/src/utils/generate-cfn-from-cdk.ts#L11) is different than the new [cdk synthesize](https://github.com/aws/aws-cdk/blob/v2.81.0/packages/aws-cdk/lib/api/cxapp/cloud-executable.ts#L70-L124) and therefore doesn't "satisfy missing context" as the synthesize function mentions. Due to this difference stacks created in amplify fail to render more complex dependency trees. The easiest example of this is when an lambda event source is mapped. The resulting policy dependency isn't applied as it should and the deploy fails. This different in output explains the reason that items like https://github.com/aws-amplify/amplify-cli/issues/10332
If the generate cfn of amplify difference is applicable across the whole library, it likely explains why people experience stuff like https://github.com/aws-amplify/amplify-cli/issues/10395.
Here is an example output:
>CREATE_FAILED
Resource handler returned message: "Invalid request provided: The provided execution role does not have permissions to call Publish on SNS (Service: Lambda, Status Code: 400, Request ID: 0" (RequestToken: 4, HandlerErrorCode: InvalidRequest)
### Expected behavior
I expect amplify to compile the cdk templates correctly.
### Reproduction steps
The easiest way is to create a lambda event source binding.
1. Create an amplify stack.
2. Add custom cdk.
3. Add an event source binding.
```
...
// Dynamo DB Tables
const customTable = new Table(this, 'customTable', {
partitionKey: { name: 'id', type: AttributeType.STRING},
timeToLiveAttribute: 'expirationDate',
tableName: Fn.join('', ['custom-table', Fn.ref('env')]),
stream: StreamViewType.OLD_IMAGE,
removalPolicy: RemovalPolicy.DESTROY,
pointInTimeRecovery: true,
});
const reactToTableLambda = new Function(this, 'reactiveLambda', {
handler: "index.handler",
code: new InlineCode('return'),
runtime: Runtime.NODEJS_16_X
});
// SNS topic for DLQ
const snsTopic = new Topic(this, 'reactiveLambdaFail', {
displayName: 'Reactive Lambda Fail',
});
// lambda event source
reactToTableLambda.addEventSource(new DynamoEventSource(customTable, {
startingPosition: StartingPosition.LATEST,
retryAttempts: 3,
onFailure: new SnsDlq(snsTopic),
}));
```
Demonstation stack here.
[amplify-scratch-cannot-deploy-this.zip](https://github.com/aws-amplify/amplify-cli/files/11587012/amplify-scratch-cannot-deploy-this.zip) which is a download of this repo: https://github.com/joekiller/amplify-scratch/tree/cannot-deploy-this
### Project Identifier
196a15c2-6185-4f3b-9126-51b1260992f5
### Log output
```
# Put your logs below this line
```
### Additional information
Below is a screenshot of the dependency difference that results on the lambda resource.
I've created a cdk enabled workflow with the amplify export functionality at the following main branch to emulate deploying cdk-custom with amplify by removing the custom cdk stack from amplify proper and deploying the resources via cdk by attaching the cdk resources to the amplify exported resources after the fact. The custom resources are only synthesized by cdk. https://github.com/joekiller/amplify-scratch
### 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
Assessment
This issue has not been assessed yet.