Deployment Pipeline for Go Applications on AWS · · 2017-07-13Amazon Web Services – Deployment...
Transcript of Deployment Pipeline for Go Applications on AWS · · 2017-07-13Amazon Web Services – Deployment...
Copyright (c) 2017 by Amazon.com, Inc. or its affiliates.
Deployment Pipeline for Go Applications is licensed under the terms of the Amazon Software License available at
https://aws.amazon.com/asl/
Deployment Pipeline for Go
Applications on AWS AWS Implementation Guide
Paul Maddox
July 2017
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 2 of 12
Contents
Overview .................................................................................................................................... 3
Cost ......................................................................................................................................... 3
Architecture Overview ........................................................................................................... 3
Implementation Considerations ............................................................................................... 5
Application Requirements ..................................................................................................... 5
Environment Configuration Files .......................................................................................... 5
Deployment Configuration .................................................................................................... 5
Automated Testing ................................................................................................................. 5
AWS CloudFormation Templates ............................................................................................. 5
Automated Deployment ............................................................................................................ 6
Prerequisites .......................................................................................................................... 6
Launch the Stack for an AWS CodeCommit Repository ....................................................... 6
Launch the Stack for a GitHub Repository ............................................................................8
Security ...................................................................................................................................... 9
Additional Resources ................................................................................................................ 9
Appendix A: Staging and Production Environments ............................................................. 10
Appendix B: Collection of Anonymous Data ........................................................................... 11
Send Us Feedback ................................................................................................................... 12
Document Revisions................................................................................................................ 12
About This Guide This implementation guide discusses architectural considerations and configuration steps for
launching the Deployment Pipeline for Go Applications solution on the Amazon Web Services
(AWS) Cloud. It includes links to AWS CloudFormation templates that launch and configure,
the AWS services required to deploy this solution using AWS best practices for security and
availability.
The guide is intended for IT infrastructure architects, administrators, and DevOps
professionals who have practical experience architecting on the AWS Cloud.
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 3 of 12
Overview Amazon Web Services (AWS) offers AWS Developer Tools, a set of services that are designed
to enable customers to rapidly and reliably deliver software. Together, these services help you
follow continuous integration and continuous delivery practices that help you securely store
and version control your application’s source code and automatically build, test, and deploy
your application to AWS or your on-premises environment.
AWS Developer Tools includes AWS CodeBuild, a managed build service that compiles
source code, runs tests, and produces software packages that are ready to deploy; AWS
CodeDeploy, a service that automates code deployments to any instance, including Amazon
EC2 instances and servers running on-premises; and AWS CodePipeline, a service that
builds, tests, and deploys your code every time there is a code change, based on the release
process models you define.
The Deployment Pipeline for Go Applications solution is an AWS-provided reference
implementation that automatically provisions and configures the AWS services necessary to
provide continuous integration and continuous delivery for applications written in Go. The
solution also deploys all the necessary AWS services to build highly available, resilient staging
and production environments for your Go application. The Deployment Pipeline for Go
Applications is designed to work with an existing Go application hosted in an AWS
CodeCommit or GitHub repository, but it also includes a sample application to create an
example environment.
The information in this guide assumes basic knowledge of applications written in Go, and
source code repositories.
Cost You are responsible for the cost of the AWS services used while running this reference
deployment. As of the date of publication, the cost for running this solution with default
settings in the US East (N. Virginia) Region is $0.14 per hour plus variable, usage-driven
hourly charges for the Application Load Balancer and data-transfer fees. Prices are subject to
change. For full details, see the pricing webpage for each AWS service you will be using in
this solution.
Architecture Overview Deploying this solution with the default parameters builds the following environment in
the AWS Cloud.
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 4 of 12
Figure 1: Deployment Pipeline for Go Applications architecture on AWS
This solution deploys a code deployment pipeline and highly available staging and
production environments to automatically test and implement features and updates to your
Go application. For more information on the staging and production environments, see
Appendix A.
The deployment pipeline consists of AWS CodePipeline, AWS CodeBuild, and AWS
CodeDeploy. AWS CodePipeline monitors your AWS CodeCommit or GitHub repository for
changes to your existing application’s code. When changes are made, AWS CodePipeline
triggers a deployment activity. Then, AWS CodeBuild runs tests, performs lint checking, and
builds the application. After the code is built successfully, AWS CodeBuild archives all build
artifacts to your existing Amazon Simple Storage Service (Amazon S3) bucket.
Note: Full build logs, including failed processes, are available in the AWS CodeBuild console.
AWS CodeDeploy then deploys your code to the staging environment. By default, the pipeline
includes a manual approval stage before final deployment. Once the code is approved, AWS
CodeDeploy deploys it to your production environment.
Important: Before you implement this solution, you must have an Amazon Elastic Compute Cloud (Amazon EC2) key pair and an Amazon S3 bucket in the AWS Region where you will deploy the solution stack.
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 5 of 12
Implementation Considerations
Application Requirements The Deployment Pipeline for Go Applications solution requires a working application written
in Go 1.8. You can use your own application, or the sample application included with this
solution.
AWS CodeBuild will compile the application using the Go 1.8 toolchain. You can modify the
AWS CodeBuild project settings to use a different version of Go after deploying the solution.
Environment Configuration Files This solution includes two configuration files: one for the staging environment
(staging.conf) and one for the production environment (production.conf). You can
modify the parameters in these files to customize the staging and production environments
that this solution creates. For example, you can modify the InstanceType parameter to use
a different Amazon Elastic Compute Cloud (Amazon EC2) instance type.
Deployment Configuration By default, this solution uses the CodeDeployDefault.OneAtATime deployment
configuration, which means that the application revisions are deployed to one instance at a
time. To use a different configuration, modify the environment configuration file included
with this solution. For more information on deployment configurations, see Working with
Deployment Configurations in AWS CodeDeploy.
Automated Testing This solution leverages AWS CodeBuild to automate code tests on every commit using the
“Go test” command. You can add additional tests by modifying the buildspec.yml file
included with this solution. The sample application included with this solution also contains
an example test.
AWS CloudFormation Templates This solution uses AWS CloudFormation to automate the deployment of the Deployment
Pipeline for Go Applications on the AWS Cloud. It includes the following CloudFormation
templates, which you can download before deployment:
go-applications-pipeline-codecommit.template: Use this
template to launch the deployment pipeline and all associated View template
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 6 of 12
components for a Go application hosted in an AWS CodeCommit repository. The default
configuration deploys AWS CodePipeline, AWS CodeBuild, AWS CodeDeploy, and the
staging and production environments, but you can also customize the template based on your
specific needs.
go-applications-pipeline-github.template: Use this template
to launch the deployment pipeline and all associated components for
a Go application hosted in a GitHub repository. The default configuration deploys AWS
CodePipeline, AWS CodeBuild, AWS CodeDeploy, and the staging and production
environments, but you can also customize the template based on your specific needs.
Automated Deployment Before you launch the automated deployment, please review the architecture, configuration,
and other considerations discussed in this guide. This section contains separate procedures
to launch this solution for applications hosted in either an AWS CodeCommit or GitHub
repository. Follow the applicable procedure to configure and deploy a deployment pipeline
for Go applications into your account.
Time to deploy: Approximately five minutes
Prerequisites Before you deploy the solution, you must have an AWS CodeCommit or GitHub repository
with your working Go application, and an Amazon Simple Storage Service (Amazon S3)
bucket.
If your application is hosted in a GitHub repository, you must create an OAuth token and fork
the repository before you deploy this solution.
If you want to migrate your existing repository from GitHub to AWS CodeCommit, see
Migrate a Git Repository to AWS CodeCommit.
Launch the Stack for an AWS CodeCommit Repository Use this procedure to deploy the deployment pipeline for applications hosted in an AWS
CodeCommit repository. Before you start, you must have an existing Amazon S3 bucket.
Note: You are responsible for the cost of the AWS services used while running this solution. See the Cost section for more details. For full details, see the pricing webpage for each AWS service you will be using in this solution.
View template
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 7 of 12
1. Sign in to the AWS Management Console and click the button to
the right to launch the go-application-pipeline-
codecommit AWS CloudFormation template.
You can also download the template as a starting point for your
own implementation.
2. The template is launched in the US East (N. Virginia) Region by default. To launch the
solution in a different AWS Region, use the region selector in the console navigation bar.
3. On the Select Template page, verify that you selected the correct template and choose
Next.
4. On the Specify Details page, assign a name to your solution stack.
5. Under Parameters, review the parameters for the template and modify them as
necessary. This solution uses the following default values.
Parameter Default Description
Application Name <Requires input> The name of the pipeline and build resources
CodePipeline S3
Bucket
<Requires input> The Amazon S3 bucket that stores build artifacts
Repository Name <Requires input> The AWS CodeCommit repository to monitor for changes
Repository Branch master The AWS CodeCommit repository branch to monitor
6. Choose Next.
7. On the Options page, choose Next.
8. On the Review page, review and confirm the settings. Be sure to check the box
acknowledging that the template will create AWS Identity and Access Management
(IAM) resources.
9. Choose Create to deploy the stack.
You can view the status of the stack in the AWS CloudFormation Console in the Status
column. You should see a status of CREATE_COMPLETE in roughly five minutes.
Note: This solution includes the solution-helper AWS Lambda function, which runs only during initial configuration or when resources are updated or deleted.
When running this solution, the solution-helper function is inactive. However, do not delete the function as it is necessary to manage associated resources.
Launch Solution for CodeCommit
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 8 of 12
Launch the Stack for a GitHub Repository Use this procedure to deploy the deployment pipeline for applications hosted in a GitHub
repository. Before you start, you must have an existing Amazon S3 bucket. You must also
create an OAuth token and fork the repository.
Note: You are responsible for the cost of the AWS services used while running this solution. See the Cost section for more details. For full details, see the pricing webpage for each AWS service you will be using in this solution.
1. Log in to the AWS Management Console and click the button to
the right to launch the go-application-pipeline-github
AWS CloudFormation template.
You can also download the template as a starting point for your
own implementation.
2. The template is launched in the US East (N. Virginia) Region by default. To launch the
solution in a different AWS Region, use the region selector in the console navigation bar.
3. On the Select Template page, verify that you selected the correct template and choose
Next.
4. On the Specify Details page, assign a name to your solution stack.
5. Under Parameters, review the parameters for the template and modify them as
necessary. This solution uses the following default values.
Parameter Default Description
Application Name <Requires input> The name of the pipeline and build resources
Build Archive S3
Bucket
<Requires input> The Amazon S3 bucket that stores build artifacts
OAuth2 Token <Requires input> The GitHub repository OAuth2Token for access to AWS
CodePipeline. Create a token with repo and
admin:repo_hook permissions at
http://github.com/settings/tokens.
Repository Owner <Requires input> The GitHub user name of the repository owner
Repository Name <Requires input> The GitHub repository to monitor for changes
Repository Branch master The GitHub repository branch to monitor
6. Choose Next.
7. On the Options page, choose Next.
Launch Solution for GitHub
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 9 of 12
8. On the Review page, review and confirm the settings. Be sure to check the box
acknowledging that the template will create AWS Identity and Access Management
(IAM) resources.
9. Choose Create to deploy the stack.
You can view the status of the stack in the AWS CloudFormation Console in the Status
column. You should see a status of CREATE_COMPLETE in roughly five minutes.
Note: This solution includes the solution-helper AWS Lambda function, which runs only during initial configuration or when resources are updated or deleted.
When running this solution, the solution-helper function is inactive. However, do not delete the function as it is necessary to manage associated resources.
Security When you build systems on AWS infrastructure, security responsibilities are shared between
you and AWS. This shared model can reduce your operational burden as AWS operates,
manages, and controls the components from the host operating system and virtualization
layer down to the physical security of the facilities in which the services operate. For more
information about security on AWS, visit the AWS Security Center.
Additional Resources
AWS services documentation
AWS CloudFormation
AWS CodeCommit
AWS CodePipeline
AWS CodeDeploy
AWS CodeBuild
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 10 of 12
Appendix A: Staging and Production
Environments In addition to the code deployment pipeline, this solution launches the following highly
available architecture for each environment (staging and production).
Figure 2: Deployment Pipeline for Go Applications infrastructure architecture
Each environment includes a Multi-AZ Amazon Virtual Private Cloud (Amazon VPC)
network topology with two public and two private subnets. Two Amazon Elastic Compute
Cloud (Amazon EC2) instances are deployed in the private subnets, and access the internet
through NAT gateways in the public subnets. An Application Load Balancer integrates with
Auto Scaling to help ensure you have capacity to meet varying levels of traffic automatically.
The first time you launch the Deployment Pipeline for Go Applications, the solution will
create the staging and production environments from scratch. On future runs, the solution
will automatically apply any updates to those environments through an AWS
CloudFormation stack update.
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 11 of 12
Appendix B: Collection of Anonymous Data This solution includes an option to send anonymous usage data to AWS. We use this data to
better understand how customers use this solution to improve the services and products
that we offer. When enabled, the following information is collected and sent to AWS during
initial stack creation:
Solution ID: The AWS solution identifier
Unique ID (UUID): Randomly generated, unique identifier for each Deployment
Pipeline for Go Applications deployment
Timestamp: Data-collection timestamp
Code Repository Data: The AWS CloudFormation template (AWS CodeCommit or
GitHub) version launched
Note that AWS will own the data gathered via this survey. Data collection will be subject to
the AWS Privacy Policy. To opt out of this feature, modify the AWS CloudFormation
template mapping section as follows:
Send:
AnonymousUsage:
Data: Yes
to
Send:
AnonymousUsage:
Data: No
Amazon Web Services – Deployment Pipeline for Go Applications on the AWS Cloud July 2017
Page 12 of 12
Send Us Feedback We welcome your questions and comments. Please post your feedback on the AWS
Solutions Discussion Forum.
You can visit our GitHub repository to download the templates and scripts for this solution,
and to share your customizations with others.
Document Revisions
Date Change In sections
July 2017 Initial release --
© 2017, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Notices
This document is provided for informational purposes only. It represents AWS’s current product offerings
and practices as of the date of issue of this document, which are subject to change without notice. Customers
are responsible for making their own independent assessment of the information in this document and any
use of AWS’s products or services, each of which is provided “as is” without warranty of any kind, whether
express or implied. This document does not create any warranties, representations, contractual
commitments, conditions or assurances from AWS, its affiliates, suppliers or licensors. The responsibilities
and liabilities of AWS to its customers are controlled by AWS agreements, and this document is not part of,
nor does it modify, any agreement between AWS and its customers.
The Deployment Pipeline for Go Applications is licensed under the terms of the Amazon Software License
available at https://aws.amazon.com/asl/.