Skip to content

Commit

Permalink
fix: auth dependency with cdkv2 (#11587)
Browse files Browse the repository at this point in the history
* fix: add a dependsOn to custom resource for auth trigger (#11504)

* fix: add a dependsOn to custom resource for auth trigger

* test: add snapshot tests to show cfn changes for dependencies

* fix: mock uuid lib in test

* fix: auth trigger template rendering

Co-authored-by: Danielle Adams <[email protected]>
  • Loading branch information
sobolk and danielleadams authored Dec 12, 2022
1 parent 96b15b4 commit f109c39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ exports.handler = async function (event, context) {
"Arn",
],
},
"Runtime": "nodejs14.x",
"Runtime": "nodejs16.x",
},
"Type": "AWS::Lambda::Function",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const CFN_TEMPLATE_FORMAT_VERSION = '2010-09-09';
*/
export class CustomResourceAuthStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: CustomResourceAuthStackProps) {
super(scope, id, props);
super(scope, id, { ...props, synthesizer: new cdk.LegacyStackSynthesizer() });
this.templateOptions.templateFormatVersion = CFN_TEMPLATE_FORMAT_VERSION;

const env = new cdk.CfnParameter(this, 'env', {
Expand Down Expand Up @@ -74,10 +74,20 @@ export class CustomResourceAuthStack extends cdk.Stack {
}

/**
* Generates a CFN template from the CDK stack
* This function renderers a full CFN template for this stack.
* It is inspired by
* https://github.com/aws/aws-cdk/blob/bd056d1d38a2d3f43efe4f857c4d38b30fb9b681/packages/%40aws-cdk/assertions/lib/template.ts#L298-L310.
* This replaces private prepareApp (from CDK v1) and this._toCloudFormation() (the latter does not function properly without the former).
*/
toCloudFormation(): Record<string, unknown> {
return this._toCloudFormation();
toCloudFormation = (): $TSAny => {
const root = this.node.root as cdk.Stage;
const assembly = root.synth();
if (!this.nestedStackParent) {
return assembly.getStackArtifact(this.artifactId).template;
}
// if this is a nested stack ( i.e. it has a parent), then just read the template as a string
const template = fs.readFileSync(path.join(assembly.directory, this.templateFile));
return JSON.parse(template.toString('utf-8'));
}
}

Expand Down

0 comments on commit f109c39

Please sign in to comment.