I am trying to reference an Amplify generated resource (a lambda function) from a custom, CDK resource and hitting the following error.
cdk-stack.ts(22,100): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Stack'.
Type 'cdkStack' is not assignable to type 'Stack'.
Types of property 'tags' are incompatible.
Property 'initialTagPriority' is missing in type 'import("<hidden>").TagManager' but required in type 'import("<hidden>").TagManager'.
How can I resolve this error? I am new to Amplify and trying to follow the online documentation and tutorials as closely as possible. This error has me stumped.
The code I am using is the following
import * as cdk from 'aws-cdk-lib';
import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper';
import { AmplifyDependentResourcesAttributes } from '../../types/amplify-dependent-resources-ref';
import { Construct } from 'constructs';
export class cdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps, amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps) {
super(scope, id, props);
/* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */
new cdk.CfnParameter(this, 'env', {
type: 'String',
description: 'Current Amplify CLI env name',
});
const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[{
category: "function",
resourceName: "myFunction"
}]
);
// ... rest of code commented out ...
}
}
The issue was bad dependencies. I had the following in package.json
"@aws-amplify/cli-extensibility-helper": "3.0.10",
"aws-cdk-lib": "~2.28.0",
but it needed to be
"@aws-amplify/cli-extensibility-helper": "3.0.10",
"aws-cdk-lib": "~2.68.0",
Note the 28
to 68
change.
@aws-amplify/cli-extensibility-helper 3.0.10
depends on aws-cdk-lib ~2.68.0