Closed Tswalano closed 1 year ago
Hey @Tswalano, thank you for reaching out. Thank you for pointing the documentation, we will work on updating the example.
The issue appears to be a duplicate of https://github.com/aws-amplify/amplify-cli/issues/13122. The issue occurs when 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
.
Could you try matching the version similar to the example here: https://github.com/aws-amplify/amplify-cli/issues/13122#issuecomment-1680929343
Does amplify custom support the cdk v2?
Amplify custom currently does support AWS CDK v2, please refer to the document providing information on the migration: https://docs.amplify.aws/cli/migration/aws-cdk-migration/
This seems to fix the issue thank you... While i still have you here can we also use APPSYNC_JS to write the resolvers in the Amplify Custom CDK instead of using VTL templating?
@Tswalano glad to hear that you were able to mitigate the issue.
While i still have you here can we also use APPSYNC_JS to write the resolvers in the Amplify Custom CDK instead of using VTL templating?
Yes, we can write a custom resource that creates JS resolvers similar to the example.
For example:
Schema
input AMPLIFY {
globalAuthRule: AuthRule = { allow: public }
} # FOR TESTING ONLY!
type Todo @model {
id: ID!
name: String!
description: String
}
type Query {
querySomething(id: String!, name: String): Todo
}
Custom resource:
const requestJS = `
import { util } from '@aws-appsync/utils'
export function request(ctx) {
return {
operation: 'GetItem',
key: util.dynamodb.toMapValues({ id: ctx.args.id }),
}
}
export function response(ctx) {
return ctx.result
}
`;
// unit resolver
const resolver = new appsync.CfnResolver(this, "custom-resolver", {
apiId: cdk.Fn.ref(retVal.api.<app-name>.GraphQLAPIIdOutput),
fieldName: "querySomething",
typeName: "Query",
dataSourceName: "TodoTable", // DataSource name
runtime: {
name: "APPSYNC_JS",
runtimeVersion: "1.0.0",
},
code: requestJS,
});
I would suggest testing this in a test/dev environments for any unexpected behaviours.
Awesome.. Thanks :)
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v18.16.1
Amplify CLI Version
12.1.1
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
Following this documentation without touching anything, the code throws:
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.
The docs are out of date and still using the CDK v1 (or is this on purpose? Does amplify custom support the cdk v2? running
amplify push
results in:Put your logs below this line