From 0b46e67d23cf8b8819a85c57dc7ebc0a2f1616dd Mon Sep 17 00:00:00 2001 From: fuu38 Date: Fri, 15 Dec 2023 23:16:20 +0900 Subject: [PATCH] fixed custom resource --- lib/candle-backend-stack.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/candle-backend-stack.ts b/lib/candle-backend-stack.ts index dfb6bc6..e7ead08 100644 --- a/lib/candle-backend-stack.ts +++ b/lib/candle-backend-stack.ts @@ -3,6 +3,7 @@ import { Construct } from 'constructs'; import * as apigateway from 'aws-cdk-lib/aws-apigateway'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import { DockerImage } from 'aws-cdk-lib'; +import * as cr from 'aws-cdk-lib/custom-resources'; export class CandleBackendStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { @@ -72,11 +73,20 @@ export class CandleBackendStack extends cdk.Stack { }); questionTable.grantWriteData(seedDataLambda) - new cdk.CustomResource(this, 'CustomResource', { - serviceToken: seedDataLambda.functionArn, - }); + const dbInitiateCR = new cr.AwsCustomResource(this, 'dbInitiateCustomResource', { + onCreate: { + service:'Lambda', + action: 'invoke', + parameters: { + FunctionName: seedDataLambda.functionArn, + }, + physicalResourceId: cr.PhysicalResourceId.of('dbInitiateCustomResource'), + }, + policy: cr.AwsCustomResourcePolicy.fromSdkCalls({resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE}), + }); + seedDataLambda.grantInvoke(dbInitiateCR); const room = api.root.addResource('room'); //room:POST