amazon-web-servicesaws-codepipelineamazon-systems-manager

Is there a way to use an SSM Parameter to provide the path for an S3 deployment in CodePipeline


So, I've got a simple CodePipeline setup that uses CodeBuild to put some artifacts together and then provisions a CloudFormation Stack.

One of the resources created is an S3 bucket for storing static files. It also creates an SSM parameter with the name of the bucket.

Currently, to deploy to the bucket I'm using an S3 stage to unpack the initial set of files. Unfortunately I can only figure out how to set the bucket manually. This works ok if the stack is already provisioned but fails if the stack is created from fresh (with a new bucket name assigned).

Is there a way I can use the SSM parameter as part of this stage that I'm not seeing?


Solution

  • If I understood you correctly, you wish to dynamically change the Bucket name of the S3 Deploy Action in CodePipeline. Currently this is not possible as this is part of the pipeline configuration [1].

    What you can do instead is take matters in your own hands, replace the S3 Deploy action with a CodeBuild action and sync the files to the S3 bucket yourself. You can read in the parameter store value using this syntax in buildspec [2]:

    env:
      parameter-store:
        key: "value"
    

    ... or use the 'aws ssm' cli 'get-parameter' command [3] on-demand.

    [1] https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-pipeline-structure.html#w498aac41c11c11c31b3

    [2] https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax-link3

    [3] https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameter.html