-
Notifications
You must be signed in to change notification settings - Fork 25
1.3
Review and ensure that you have setup your development environment before going through the steps below.
- From AWS Cloud9, create a directory and file:
mkdir ~/environment/ceoa/codecommit-files
cd ~/environment/ceoa/codecommit-files
touch ceoa-1-pipeline-cfn.yml
- Open the file and paste the template configuration below and save.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple CodePipeline example with CodeCommit and Approval
Parameters:
EmailAddress:
Description: Email Address for sending SNS notifications for CodeCommit
Type: String
RepositoryBranch:
Description: The name of the branch for the CodeCommit repo
Type: String
Default: master
AllowedPattern: "[\\x20-\\x7E]*"
ConstraintDescription: Can contain only ASCII characters.
CodeCommitS3Bucket:
Description: S3 bucket that holds zip of source code for CodeCommit Repo
Type: String
CodeCommitS3Key:
Description: zipfile key located in CodeCommitS3Bucket
Type: String
Resources:
MySNSTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint:
Ref: EmailAddress
Protocol: email
CodeCommitRepo:
Type: AWS::CodeCommit::Repository
Properties:
RepositoryName:
Ref: AWS::StackName
RepositoryDescription: CodeCommit Repository for cfn_nag solution
Code:
S3:
Bucket: !Ref CodeCommitS3Bucket
Key: !Ref CodeCommitS3Key
Triggers:
- Name: MasterTrigger
CustomData:
Ref: AWS::StackName
DestinationArn:
Ref: MySNSTopic
Events:
- all
CodePipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: codepipeline-service
PolicyDocument:
Statement:
- Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:GetBucketVersioning
Resource: "*"
Effect: Allow
- Action:
- s3:PutObject
Resource:
- arn:aws:s3:::codepipeline*
Effect: Allow
- Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:GetBucketVersioning
- s3:PutObject
- iam:PassRole
Resource: "*"
Effect: Allow
- Action:
- codecommit:*
- codebuild:*
Resource: "*"
Effect: Allow
Version: '2012-10-17'
PipelineBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
RoleArn: !GetAtt CodePipelineRole.Arn
Stages:
- Name: Source
Actions:
- InputArtifacts: []
Name: Source
ActionTypeId:
Category: Source
Owner: AWS
Version: '1'
Provider: CodeCommit
OutputArtifacts:
- Name: MyApp
Configuration:
BranchName:
Ref: RepositoryBranch
RepositoryName:
Ref: AWS::StackName
RunOrder: 1
- Name: Deploy
Actions:
- Name: Deploy
ActionTypeId:
Category: Approval
Owner: AWS
Version: '1'
Provider: Manual
Configuration:
ExternalEntityLink: https://mphasis.com
RunOrder: 1
ArtifactStore:
Type: S3
Location: !Ref PipelineBucket
Outputs:
PipelineUrl:
Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline}
Description: CodePipeline URL
In this section, you will zip and upload all of the source files to the S3 bucket you created when setting up your development environment. This way the ceoa-1-pipeline.yml template initializes the CodeCommit repository that is automatically provisioned by the stack.
From your AWS Cloud9 environment, type the following:
cd ~/environment/ceoa/codecommit-files
zip ceoa-1-examples.zip *.*
aws s3 sync ~/environment/ceoa/codecommit-files s3://ceoa-$(aws sts get-caller-identity --output text --query 'Account')
From your AWS Cloud9 environment, type the following (replacing you@example.com and REGIONCODE with the appropriate values):
aws cloudformation create-stack --stack-name ceoa-1-pipeline-cfn --template-body file:///home/ec2-user/environment/ceoa/codecommit-files/ceoa-1-pipeline-cfn.yml --parameters ParameterKey=EmailAddress,ParameterValue=you@example.com ParameterKey=CodeCommitS3Bucket,ParameterValue=ceoa-$(aws sts get-caller-identity --output text --query 'Account') ParameterKey=CodeCommitS3Key,ParameterValue=ceoa-1-examples.zip --capabilities CAPABILITY_NAMED_IAM --disable-rollback
- Once the CloudFormation stack is successful, select the checkbox next to the stack and click the Outputs tab.
- From the Outputs tab, click on the PipelineUrl output.
Get the generated pipeline name by going to CodePipeline Console.
From AWS Cloud9 terminal, type the following (replacing YOURPIPELINENAME with the generated name):
aws codepipeline get-pipeline --name YOURPIPELINENAME
Go to Cleanup to remove any resources you created in this sublesson.
- Introduction
- Labs
- The Current State of Encryption
- Setup Development Environment
- Lesson 1: Automating AWS Resources
- Lesson 2: Key Management
- Lesson 3: Developing with Encryption
- Lesson 4: Encryption in Transit
- Lesson 5: Encryption at Rest
- Lesson 6: Detecting Encrypted Resources
- Lesson 7: Logging and Searching KMS Keys
- Lesson 8: Continuous Encryption
- Summary