CodePipeline built-in cfn provider has a limitation that a cfn template size can't exceed 51kb.
aws-codepipeline-cfn-provider
solves this problem by providing an alternative cfn provider implemented as a Lambda.
Instead of passing templates directly, it uploads templates to s3 bucket before creating a stack so it can be used to deploy stacks from templates with size > 51kb.
Lambda requires an s3 bucket used to store cfn templates.
The bucket name is set by PIPELINE_TEMPLATES_BUCKET
environment variable.
aws-codepipeline-cfn-provider uses Pipenv
to manage Python dependencies.
pipenv --three
pipenv install
Modify bucket name and bucket key in s3_deploy.sh
script
Run s3_deploy.sh
to generate a zip package and upload file to S3 bucket.
Create a Lambda in AWS console using zipped package from s3 bucket.
Lambda handler name should be set to: pipeline_lambda/pipeline_lambda.handler
aws-codepipeline-cfn-provider requires at least the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"codepipeline:PutJobFailureResult",
"codepipeline:PutJobSuccessResult"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"cloudformation:DescribeStacks",
"cloudformation:DeleteStack",
"cloudformation:CreateStack",
"cloudformation:UpdateStack",
"cloudformation:DescribeChangeSet",
"cloudformation:CreateChangeSet",
"cloudformation:ExecuteChangeSet",
"cloudformation:SetStackPolicy",
"cloudformation:DeleteChangeSet",
"iam:PassRole"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::your-pipeline-templates-bucket/*"
],
"Effect": "Allow"
},
{
"Action": [
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::your-pipeline-templates-bucket"
],
"Effect": "Allow"
}
]
}
User parameters are used to configure lambda and should be passed in a JSON format:
{
"ActionMode": "operation_name", [CREATE_UPDATE, DELETE_ONLY, CHANGE_SET_REPLACE, CHANGE_SET_EXECUTE]
"StackName": "stack_name",
"ChangeSetName": "change_set_name",
"TemplatePath": "ArtifactName::TemplateFile",
"ConfigPath": "ArtifactName::ConfigFile",
"RoleArn": "cfn_role_arn",
"OutputFileName": "artifact_output_file_name" (output.json is default),
"ParameterOverrides": {"param": "value"}
"Capabilities": ["CAPABILITY_NAMED_IAM", "CAPABILITY_IAM"] list or string
}
PIPELINE_TEMPLATES_BUCKET
- S3 bucket used to upload cfn templates to
{
"StackName": "test_stack",
"ActionMode": "DELETE_ONLY,
"RoleArn": "cfn_role_arn",
}
{
"ActionMode": "CREATE_UPDATE",
"StackName": "test_stack",
"RoleArn": "cfn_role_arn",
"TemplatePath": "MyApp::template.json",
"ConfigPath": "MyApp::config.json",
"ParameterOverrides": {
"param1": "value1",
"param2": { "Fn::GetParam" : [ "MyApp", "config2.json", "param2" ] }
}
}
{
"ActionMode": "CHANGE_SET_REPLACE",
"StackName": "test_stack",
"ChangeSetName": "test_change_set",
"RoleArn": "cfn_role_arn",
"TemplatePath": "MyApp::template.json",
"ConfigPath": "MyApp::config.json",
"ParameterOverrides": {
"param1": "value1",
"param2": { "Fn::GetParam" : [ "MyApp", "config2.json", "param2" ] }
}
}
{
"ActionMode": "CHANGE_SET_EXECUTE",
"StackName": "test_stack",
"ChangeSetName": "test_change_set",
"RoleArn": "cfn_role_arn"
"OutputFileName": "out.json"
}
Apache License 2.0
Copyright Nordcloud OY