Skip to content

Commit 8bbdbc4

Browse files
committed
Add initial CloudFormation templates for CI/CD
1 parent 4a861b0 commit 8bbdbc4

7 files changed

+1769
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,35 @@ The ci_tools folder contains the following tools for use with AWS Lambda and Ama
3333

3434
Contains an appspec.yml file and deploy_scripts folder for deploying the service with AWS CodeDeploy.
3535

36+
### CloudFormation
37+
38+
Create a CodeCommit repository called 'aws-codebuild-samples' and push this sample code into the repo. Then spin up all of the above easily with CloudFormation.
39+
40+
Create the continuous deployment stack, with a CodePipeline pipeline:
41+
```
42+
aws cloudformation create-stack --stack-name aws-codebuild-samples --template-body file://cloudformation/continuous-deployment.yml --capabilities CAPABILITY_NAMED_IAM
43+
44+
aws cloudformation wait stack-create-complete --stack-name aws-codebuild-samples
45+
46+
aws cloudformation describe-stacks --stack-name aws-codebuild-samples --query 'Stacks[0].Outputs[?OutputKey==`PipelineConsoleUrl`].OutputValue' --output text
47+
```
48+
49+
Wait for the pipeline to finish deploying, then access the Test and Prod stack applications:
50+
```
51+
aws cloudformation describe-stacks --stack-name aws-codebuild-samples-test-stack --query 'Stacks[0].Outputs[?OutputKey==`Url`].OutputValue' --output text
52+
53+
aws cloudformation describe-stacks --stack-name aws-codebuild-samples-prod-stack --query 'Stacks[0].Outputs[?OutputKey==`Url`].OutputValue' --output text
54+
```
55+
56+
Set up continuous integration for the application:
57+
```
58+
aws cloudformation create-stack --stack-name aws-codebuild-samples-nightly-checks --template-body file://cloudformation/continuous-integration-nightly-checks.yml --capabilities CAPABILITY_NAMED_IAM
59+
60+
aws cloudformation create-stack --stack-name aws-codebuild-samples-branch-checks --template-body file://cloudformation/continuous-integration-branch-checks.yml --capabilities CAPABILITY_NAMED_IAM
61+
62+
aws cloudformation create-stack --stack-name aws-codebuild-samples-pull-request-checks --template-body file://cloudformation/continuous-integration-pull-request-checks.yml --capabilities CAPABILITY_NAMED_IAM
63+
```
64+
3665
## License
3766

3867
This library is licensed under the Apache 2.0 License.

cloudformation/application.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
Description:
2+
This template sets up the sample calculator application on an AutoScaling group,
3+
behind an Application Load Balancer, with a CodeDeploy application.
4+
5+
Parameters:
6+
SharedResourceStack:
7+
Description: Name of an active CloudFormation stack that contains shared resources, such as the VPC.
8+
Type: String
9+
MinLength: 1
10+
MaxLength: 255
11+
AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
12+
Default: CodeBuildSampleSharedResources
13+
Stage:
14+
Description: Release stage
15+
Type: String
16+
MinLength: 1
17+
MaxLength: 255
18+
AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
19+
Default: Prod
20+
21+
Resources:
22+
DeploymentGroup:
23+
Type: "AWS::CodeDeploy::DeploymentGroup"
24+
Properties:
25+
DeploymentGroupName: !Join
26+
- '-'
27+
- - !Ref 'AWS::StackName'
28+
- DeploymentGroup
29+
ApplicationName:
30+
Fn::ImportValue:
31+
!Sub "${SharedResourceStack}:CodeDeployApplication"
32+
ServiceRoleArn:
33+
Fn::ImportValue:
34+
!Sub "${SharedResourceStack}:CodeDeployRole"
35+
DeploymentConfigName: CodeDeployDefault.AllAtOnce
36+
AutoScalingGroups:
37+
- Ref: AutoScalingGroup
38+
39+
AutoScalingGroup:
40+
Type: AWS::AutoScaling::AutoScalingGroup
41+
Properties:
42+
HealthCheckType: ELB
43+
HealthCheckGracePeriod: 300
44+
MinSize: 3
45+
MaxSize: 3
46+
LaunchConfigurationName:
47+
Fn::ImportValue:
48+
!Sub "${SharedResourceStack}:LaunchConfig"
49+
VPCZoneIdentifier:
50+
Fn::Split:
51+
- ","
52+
- Fn::ImportValue:
53+
!Sub "${SharedResourceStack}:PrivateSubnets"
54+
TargetGroupARNs:
55+
- Ref: LoadBalancerTargetGroup
56+
Tags:
57+
- Key: Name
58+
Value: !Join
59+
- "-"
60+
- - Fn::ImportValue:
61+
!Sub "${SharedResourceStack}:ApplicationName"
62+
- !Ref Stage
63+
PropagateAtLaunch: true
64+
65+
LoadBalancerListener:
66+
Type: AWS::ElasticLoadBalancingV2::Listener
67+
Properties:
68+
DefaultActions:
69+
-
70+
Type: forward
71+
TargetGroupArn:
72+
Ref: LoadBalancerTargetGroup
73+
LoadBalancerArn:
74+
Ref: LoadBalancer
75+
Port: 80
76+
Protocol: HTTP
77+
78+
LoadBalancer:
79+
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
80+
Properties:
81+
Scheme: internet-facing
82+
Subnets:
83+
Fn::Split:
84+
- ","
85+
- Fn::ImportValue:
86+
!Sub "${SharedResourceStack}:PublicSubnets"
87+
SecurityGroups:
88+
- Fn::ImportValue:
89+
!Sub "${SharedResourceStack}:PublicHttpIngressSecurityGroup"
90+
91+
LoadBalancerTargetGroup:
92+
Type: AWS::ElasticLoadBalancingV2::TargetGroup
93+
Properties:
94+
HealthCheckIntervalSeconds: 30
95+
UnhealthyThresholdCount: 2
96+
HealthyThresholdCount: 2
97+
Port: 8080
98+
Protocol: HTTP
99+
VpcId:
100+
Fn::ImportValue:
101+
!Sub "${SharedResourceStack}:VPC"
102+
103+
Outputs:
104+
Url:
105+
Description: Calculator application URL
106+
Value:
107+
Fn::Sub: 'http://${LoadBalancer.DNSName}'
108+
DeploymentGroup:
109+
Description: Calculator application deployment group
110+
Value: !Ref DeploymentGroup

0 commit comments

Comments
 (0)