Asset Parameters in Cloud Formation template generated by AWS CDK

0

I am attempting to use AWS CDK to create a CloudFormation template that is reusable. The template (generated from the "cdk synth" command) contains some resources, a lambda function and a custom resource to trigger the lambda function. It also contains some parameters to be fetched from the user for passing to the lambda. Since CDK generates and includes "asset" parameters like Asset for S3 Bucket, S3 Key and Artifact Hash in the template related to the Lambda assets, the template is not really reusable unless we use CDK to deploy the app. We would like to be able to use this synthesized CloudFormation template to create stacks independently. Is this possible? Is there a way to work around the Asset Parameters in the cdk app so that we can generate reusable templates? Thank you!

질문됨 2년 전890회 조회
2개 답변
0

One option would be to change the way you build Lambda functions in your stack code. Instead of using new lambda.Function(), you could use lambda.fromFunctionName() or lambda.fromFunctionArn() to point to an existing Lambda function that you have uploaded previously using some other method.

However, this is not a best practice. The better practice would be to deploy the stack using AWS CodeBuild, which can run your CDK application for you in a Linux container context.

AWS
전문가
답변함 2년 전
  • Thank you @Michael_F! So the lambda itself should probably not be deployed as part of this stack and rather referenced by its ARN, is that right? Could you please elaborate on why this is not a best practice, and why the stack should be deployed using AWS CodeBuild? As I mentioned earlier, we're mainly interested in the template generated by "cdk synth" and would like that template to be reusable so that we can use it independently to deploy stacks in CloudFormation. We also want to make the template available through the AWS marketplace. Thanks!

0

I have pretty much the same question as I also want to use the CloudFormation template in the AWS Marketplace. I'm currently building lambdas as Assets and it's convenient, but they end up in a private stack-specific S3 bucket. My understanding is that for the lambdas to be accessible by customers deploying the template, they need to be built "out of stack" (e.g. using a build script) and uploaded to a public S3 bucket. Is that correct?

답변함 8달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠