CodePipeline unable to locate SAM template yaml file

Brooks Source

I'm attempting to setup AWS Codepipeline with a Cloudformation SAM stack that deploys to a Lambda and am doing this via the Pipeline console. The pipeline passes the clone from Codecommit process and the build process with Codebuild, however fails on the deploy with Cloudformation.

I get the following error message:

Action execution failed Invalid TemplatePath: MyAppBuild::samTemplate.yml

I've been following the documentation ( pretty closely and in field 16 of the codepipeline setup form (Template File) I have been putting samTemplate.yml.

I also have samTemplate.yml in the root of my repo (which is also the root of the project).

I've matched the Codebuild output artifact name with the Cloudformation input artifact name and they match exactly.

Am I missing something here? How do I get the Cloudformation deploy process to recognize the sam template?

EDIT 1 I've switched to using Codestar instead of directly using CodePipeline. Nothing special in my buildspec.yml, but it's below if anyone's interested.

version: 0.2

      - echo "install"
      - echo "pre_build"
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template template-export.json
  type: zip
    - template-export.json

One thing to keep in mind for anyone new to CodeBuild, the zip file that gets created as a result is of the root level directory of your build operations and IS the zip file that gets transferred to final deployment (in my case, Lambda).



answered 1 year ago TimB #1

I believe the output of the build stage is what needs to be passed into the CloudFormation action.

In the tutorial the build output is called NewSamTemplate.yaml

So try updating your TemplatePath to MyAppBuild::NewSamTemplate.yml

answered 1 year ago D.Sajwan #2

You need to add aws cloudformation package command in you buildspec.yml.

 aws cloudformation package --debug --template-file <YourSamTemplate.yml> --s3-bucket <YourbucketName> --output-template-file <YourOutputSamTemplate.yml>

where YourSamTemplate.yml is the name of samTemplate.yml in your project root. and YourOutputSamTemplate.yml is the new name which you eant to give your output file after cloud formation package command is done.

Then in the next stage you need to define your input-artifact as output of your aws codebuild stage and then use this input-artifact to map your template.


comments powered by Disqus