Migration to cdk: How to include existing Serverless::Function yaml files in cdk codepipeline

1

We have several yaml files that contain Type: AWS::Serverless::Function and CodeUri: ../some-module/dist/. We deploy these using CLI and the following commands:

aws cloudformation package --template input.yaml --output-template-file /build/output.yaml --s3-bucket <some-bucket> --s3-prefix <some path>
aws cloudformation deploy --template-file /build/output.yaml --stack-name <some stack>  --capabilities CAPABILITY_NAMED_IAM  --parameter-overrides <parameters>

We are in the process of migrating to CDK2 and CodePipeline, and as a first step we just want to reuse the existing yaml files in CDK2.

When we include the original yaml file using:

new CfnInclude(this, 'stack', {
  templateFile: 'input.yaml',
  parameters
});

We get the following error message:

Transform AWS::Serverless failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [X] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.

The way we interpret this is that the package step that we do when we're using CLI is not happening automatically when we just include the original yaml with CfnInclude, and we are doing it wrong.

What is the proper way to include such yaml file in CDK2?

Thanks in advance :) -wab

wab
已提問 2 年前檢視次數 91 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南