The pipeline.yaml
CloudFormation template deploys a pipeline that:
- Reads the contents of the directory in the GitHub repository
- Uses the cfn-nag tool as a linter
- Deploys a CloudFormation template. This template is the
cfn-template.yaml
file, which upon deployment creates a simple S3 bucket. The template is deployed into the same account as the CodePipeline is in, however with appropriate IAM permissions, cross-account deployment can be configured. TheDeploymentRole
is deployed from a separate file,deployment-role.yaml
, to allow for this possibility. - Runs tests. Currently the pipeline saves the outputs of the CloudFormation deployment into a file and reads it.
- Passes artifacts, such as the artifact that is passed to the final testing stage in the pipeline.
To deploy the CodePipeline template, you will need:
- the AWS CLI installed and configured (how to do this is here in AWS documentation)
- to deploy the
deployment-role.yaml
file, which provides the permissions necessary for the pipeline to deploy a CloudFormation stack - A CodeStart connection established in the account you want to create a CodePipeline in. More info available on AWS, here.
- a separate JSON file stored within a
parameters
directory and updated to provide the following parameters:
[
"ProductName=your-product-name",
"Environment=your-environment-such-as-dev",
"GitHubBranchName=your-github-branch-name",
"TargetAccountForCFnDeployment=current-account-number-to-deploy-the-s3-bucket-yaml-file-into",
"GitHubOwner=your-GitHub-name",
"GitHubRepoName=your-GitHub-repo-name",
"GitHubConnectionArn=arn:aws:codestar-connections:<region>:<account-number>:connection/<connection-id>"
]
This role gives the pipeline permission to deploy a CloudFormation template into an AWS account.
Deploy from the AWS CLI:
aws cloudformation deploy \
--template-file "deployment-role.yaml" \
--stack-name <your-stack-name> \
--parameter-overrides file://role-parameters/<parameter-file-name>.json \
--profile <your-aws-profile-name>
--capabilities CAPABILITY_NAMED_IAM
Deploy from the AWS CLI:
aws cloudformation deploy \
--template-file "pipeline.yaml" \
--stack-name <your-stack-name> \
--parameter-overrides file://parameters/<parameter-file-name>.json \
--profile <your-aws-profile-name> \
--capabilities CAPABILITY_NAMED_IAM