-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Amplify cdk-stack output missing dependencies which are generated during cdk synth #12702
Comments
Hey @joekiller, thank you for reaching and apologies in the delay in a response. Tried reproducing the issue with the following steps.
additionally, i did not observe an dependsOn in the generated cfn template Could you provide us some additional information that would assist us in reproduction. Additionally, could you let us know the permissions on the aws profile that the CDK app utilizes. |
@ykethan please create an independent cdk project and add the same resource declarations to that project and do a If you export the amplify project and use the amplify exported backend then, yes, you will not see the dependencies as that literally imports via CfnImport. The import amplify backend doesn't render the proper stack either as it is using CfnImport, a verbatim copy of what amplify created. |
You are correct that sometimes the stack will deploy as is because there's a race between the creation of the eventSource and attachment of the policy to the role. If you examine the resource creation order as cloud formation proceeds you will observe that the attachment of the role creation starts at the same time as creating the eventSource. The attachment of the policy should always precede the creation of the eventSource and to ensure the policy is always attached prior to the eventSource mapping one must make the lambda itself depend on the policy. Having the lambda depend on the policy ensures the policy statement is always created and attached to the role prior to creating the lambda which has the mapping. The lambda does have the role but the policy attachment to the role and eventSource is the race. If you want, you can examine the SNS policy and see that it is attached to the role during the same create |
For anyone using my workaround please note that you must remove the custom resource from the Amplify stack and only define it in the cdk project. You can export all non-custom resources from amplify and then declare the cdk resources in a separate stack. My workaround attaches and synthesizes the custom stack in the cdk stack only. |
@ykethan when I created the example please observe that for the cdk stack i include the same code that the Amplify cli uses to synthesize the stack however I do not use the import cdk resource. I just included the custom-cdk in the tsconfig so that the cdk application cdk/app/cdk.ts could synthesize the same stack that Amplify does. In my example the cdk stack doesn't use aws-amplify/cdk-exported-backend at all. |
Hey @joekiller, thank you for the information. I was able to reproduce the issue. It appears the Amplify CLI provided synth version is causing this behaviour. Marking this as bug for further improvements. |
@ykethan I also have this problem, trying to use |
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 and then generates cfn is different than the new cdk synthesize 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 #10332
If the generate cfn of amplify difference is applicable across the whole library, it likely explains why people experience stuff like #10395.
Here is an example output:
Expected behavior
I expect amplify to compile the cdk templates correctly.
Reproduction steps
The easiest way is to create a lambda event source binding.
Demonstation stack here.
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
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:
The text was updated successfully, but these errors were encountered: