amplify-cli
amplify-cli copied to clipboard
custom CDK Stack type clash after upgrading aws-cdk-lib version
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v20.5.0
Amplify CLI Version
12.2.2
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
Describe the bug
Run amplify add custom
-> AWS CDK
In the generated AWS CDK code, uncomment the example on accessing other Amplify Resources:
// Access other Amplify Resources
const retVal:AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[
{category: <insert-amplify-category>, resourceName: <insert-amplify-resourcename>},
]
);
Observe that this
is triggering a compile error:
Argument of type 'this' is not assignable to parameter of type 'Stack'.
Property 'toYamlString' is missing in type 'cdkStack' but required in type 'Stack'.ts(2345)
stack.d.ts(328, 5): 'toYamlString' is declared here.
Expected behavior
No compile error when using example code. Ability to access Amplify generated resources in custom CDK code.
Reproduction steps
Please see steps above
Project Identifier
No response
Log output
# Put your logs below this line
Additional information
No response
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.
Hey @fjnoyp :wave: thanks for raising this! I was able to reproduce this by adding a custom resource using CLI version 12.2.3. I am currently looking into a workaround, however after upgrading all custom resource dependencies and the CLI I am still encountering this. Marking as a bug and "investigating" for the workaround
Hey @fjnoyp this appears to be an issue where there is a version mismatch between the version of aws-cdk-lib
the extensibility helper depends on and the version that is installed directly to the custom resource's package.json
As a workaround, can you match the version of aws-cdk-lib
with the version the extensibility helper depends on? For example,
{
"name": "custom-resource",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@aws-amplify/cli-extensibility-helper": "^3.0.14",
"aws-cdk-lib": "~2.80.0",
"constructs": "^10.2.69"
},
"devDependencies": {
"typescript": "^5.1.6"
}
}
Thanks @josefaidt I will investigate that fix. However, the Amplify team wants to release a custom CDK script that our customers can simply copy/paste into their application.
While we can instruct customers to make this additional modification, we anticipate this can add extra confusion for them.
Do you have a general timeline/idea of when you can investigate and commit to a fix here?
Hi @josefaidt regarding your suggested fix to downgrade, it appears your library methods have changed as well.
For example now the import of AmplifyHelpers fails and I'm unsure what else to actually use here:
import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper';
It looks like your documentation refers to this import too:
https://docs.amplify.aws/cli/custom/cdk/
@josefaidt is there a plan to update the version of "@aws-amplify/cli-extensibility-helper" to support a higher version of "aws-cdk-lib"? How do I find out what versions of "aws-cdk-lib" are supported by "@aws-amplify/cli-extensibility-helper", I can't seem to find it in the changelogs.
In my particular scenario, I'm currently defining my bedrock/knowledge base infrastructure using CDK:
"@aws-amplify/cli-extensibility-helper": "^3.0.24",
"@cdklabs/generative-ai-cdk-constructs": "0.1.72",
"aws-cdk-lib": "2.116.0",
However "@cdklabs/generative-ai-cdk-constructs" is also built upon a specific version of "aws-cdk-lib". I need to use the latest version of "@cdklabs/generative-ai-cdk-constructs" as it is the only version that includes the bedrock apis.
Using the above versions I am also getting:
Argument of type 'this' is not assignable to parameter of type 'Stack'.
I have the same questions as @khlling. I'd like to be able to use the Distributed Map enhancements recently add to CDK and was disappointed to find that this library is several months behind supporting core CDK.