├── .gitignore ├── images ├── architecture.pdf └── architecture.png ├── bin ├── get_amis.sh └── deploy ├── NOTICE ├── templates ├── vpc.yaml ├── load-balancer.yaml ├── service.yaml ├── ecs-cluster.yaml └── deployment-pipeline.yaml ├── ecs-refarch-continuous-deployment.yaml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | -------------------------------------------------------------------------------- /images/architecture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/ecs-refarch-continuous-deployment/HEAD/images/architecture.pdf -------------------------------------------------------------------------------- /images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/awslabs/ecs-refarch-continuous-deployment/HEAD/images/architecture.png -------------------------------------------------------------------------------- /bin/get_amis.sh: -------------------------------------------------------------------------------- 1 | echo "AWSRegionToAMI:" 2 | 3 | for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text) 4 | do 5 | echo " ${region}:" 6 | echo -n " AMI: " 7 | 8 | aws ec2 describe-images \ 9 | --owners amazon \ 10 | --query 'reverse(sort_by(Images[?Name != `null`] | [?contains(Name, `amazon-ecs-optimized`) == `true`], &CreationDate))[:1].ImageId' \ 11 | --output text \ 12 | --region $region 13 | done 14 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at 4 | 5 | http://aws.amazon.com/apache2.0/ 6 | 7 | or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 8 | 9 | ecs-refarch-continuous-deployment 10 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 11 | -------------------------------------------------------------------------------- /bin/deploy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit -o xtrace 4 | 5 | aws s3api head-bucket --bucket "$1" || aws s3 mb "s3://${1}" 6 | 7 | aws s3api put-bucket-policy --bucket "$1" \ 8 | --policy "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:GetObject\",\"s3:GetObjectVersion\"],\"Resource\":\"arn:aws:s3:::${1}/*\"},{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:ListBucket\",\"s3:GetBucketVersioning\"],\"Resource\":\"arn:aws:s3:::${1}\"}]}" \ 9 | 10 | aws s3api put-bucket-versioning --bucket "$1" --versioning-configuration Status=Enabled 11 | 12 | aws s3 cp ecs-refarch-continuous-deployment.yaml "s3://${1}" 13 | 14 | aws s3 cp --recursive templates/ "s3://${1}/templates" 15 | -------------------------------------------------------------------------------- /templates/vpc.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: 2010-09-09 3 | 4 | 5 | Parameters: 6 | Name: 7 | Type: String 8 | 9 | VpcCIDR: 10 | Type: String 11 | 12 | Subnet1CIDR: 13 | Type: String 14 | 15 | Subnet2CIDR: 16 | Type: String 17 | 18 | 19 | Resources: 20 | VPC: 21 | Type: AWS::EC2::VPC 22 | Properties: 23 | CidrBlock: !Ref VpcCIDR 24 | Tags: 25 | - Key: Name 26 | Value: !Ref Name 27 | 28 | InternetGateway: 29 | Type: AWS::EC2::InternetGateway 30 | Properties: 31 | Tags: 32 | - Key: Name 33 | Value: !Ref Name 34 | 35 | InternetGatewayAttachment: 36 | Type: AWS::EC2::VPCGatewayAttachment 37 | Properties: 38 | InternetGatewayId: !Ref InternetGateway 39 | VpcId: !Ref VPC 40 | 41 | Subnet1: 42 | Type: AWS::EC2::Subnet 43 | Properties: 44 | VpcId: !Ref VPC 45 | AvailabilityZone: !Select [ 0, !GetAZs ] 46 | MapPublicIpOnLaunch: true 47 | CidrBlock: !Ref Subnet1CIDR 48 | Tags: 49 | - Key: Name 50 | Value: !Sub ${Name} (Public) 51 | 52 | Subnet2: 53 | Type: AWS::EC2::Subnet 54 | Properties: 55 | VpcId: !Ref VPC 56 | AvailabilityZone: !Select [ 1, !GetAZs ] 57 | MapPublicIpOnLaunch: true 58 | CidrBlock: !Ref Subnet2CIDR 59 | Tags: 60 | - Key: Name 61 | Value: !Sub ${Name} (Public) 62 | 63 | RouteTable: 64 | Type: AWS::EC2::RouteTable 65 | Properties: 66 | VpcId: !Ref VPC 67 | Tags: 68 | - Key: Name 69 | Value: !Ref Name 70 | 71 | DefaultRoute: 72 | Type: AWS::EC2::Route 73 | Properties: 74 | RouteTableId: !Ref RouteTable 75 | DestinationCidrBlock: 0.0.0.0/0 76 | GatewayId: !Ref InternetGateway 77 | 78 | Subnet1RouteTableAssociation: 79 | Type: AWS::EC2::SubnetRouteTableAssociation 80 | Properties: 81 | RouteTableId: !Ref RouteTable 82 | SubnetId: !Ref Subnet1 83 | 84 | Subnet2RouteTableAssociation: 85 | Type: AWS::EC2::SubnetRouteTableAssociation 86 | Properties: 87 | RouteTableId: !Ref RouteTable 88 | SubnetId: !Ref Subnet2 89 | 90 | 91 | Outputs: 92 | Subnets: 93 | Value: !Join [ ",", [ !Ref Subnet1, !Ref Subnet2 ] ] 94 | VpcId: 95 | Value: !Ref VPC 96 | -------------------------------------------------------------------------------- /templates/load-balancer.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: 2010-09-09 3 | 4 | 5 | Parameters: 6 | LaunchType: 7 | Type: String 8 | Default: Fargate 9 | AllowedValues: 10 | - Fargate 11 | - EC2 12 | 13 | Subnets: 14 | Type: List 15 | 16 | VpcId: 17 | Type: String 18 | 19 | 20 | Conditions: 21 | EC2: !Equals [ !Ref LaunchType, "EC2" ] 22 | 23 | 24 | Resources: 25 | SecurityGroup: 26 | Type: "AWS::EC2::SecurityGroup" 27 | Properties: 28 | GroupDescription: !Sub ${AWS::StackName}-alb 29 | SecurityGroupIngress: 30 | - CidrIp: "0.0.0.0/0" 31 | IpProtocol: "TCP" 32 | FromPort: 80 33 | ToPort: 80 34 | VpcId: !Ref VpcId 35 | 36 | LoadBalancer: 37 | Type: AWS::ElasticLoadBalancingV2::LoadBalancer 38 | Properties: 39 | Subnets: !Ref Subnets 40 | SecurityGroups: 41 | - !Ref SecurityGroup 42 | 43 | LoadBalancerListener: 44 | Type: AWS::ElasticLoadBalancingV2::Listener 45 | Properties: 46 | LoadBalancerArn: !Ref LoadBalancer 47 | Port: 80 48 | Protocol: HTTP 49 | DefaultActions: 50 | - Type: forward 51 | TargetGroupArn: !Ref TargetGroup 52 | 53 | TargetGroup: 54 | Type: AWS::ElasticLoadBalancingV2::TargetGroup 55 | DependsOn: LoadBalancer 56 | Properties: 57 | VpcId: !Ref VpcId 58 | Port: 80 59 | Protocol: HTTP 60 | Matcher: 61 | HttpCode: 200-299 62 | HealthCheckIntervalSeconds: 10 63 | HealthCheckPath: / 64 | HealthCheckProtocol: HTTP 65 | HealthCheckTimeoutSeconds: 5 66 | HealthyThresholdCount: 2 67 | TargetType: !If [ EC2, "instance", "ip" ] 68 | TargetGroupAttributes: 69 | - Key: deregistration_delay.timeout_seconds 70 | Value: 30 71 | 72 | ListenerRule: 73 | Type: AWS::ElasticLoadBalancingV2::ListenerRule 74 | Properties: 75 | ListenerArn: !Ref LoadBalancerListener 76 | Priority: 1 77 | Conditions: 78 | - Field: path-pattern 79 | Values: 80 | - / 81 | Actions: 82 | - TargetGroupArn: !Ref TargetGroup 83 | Type: forward 84 | 85 | 86 | Outputs: 87 | TargetGroup: 88 | Value: !Ref TargetGroup 89 | 90 | ServiceUrl: 91 | Description: URL of the load balancer for the sample service. 92 | Value: !Sub http://${LoadBalancer.DNSName} 93 | 94 | SecurityGroup: 95 | Value: !Ref SecurityGroup 96 | -------------------------------------------------------------------------------- /templates/service.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: 2010-09-09 3 | 4 | 5 | Parameters: 6 | Cluster: 7 | Type: String 8 | 9 | DesiredCount: 10 | Type: Number 11 | Default: 1 12 | 13 | LaunchType: 14 | Type: String 15 | Default: Fargate 16 | AllowedValues: 17 | - Fargate 18 | - EC2 19 | 20 | TargetGroup: 21 | Type: String 22 | 23 | SourceSecurityGroup: 24 | Type: AWS::EC2::SecurityGroup::Id 25 | 26 | Subnets: 27 | Type: List 28 | 29 | 30 | Conditions: 31 | Fargate: !Equals [ !Ref LaunchType, "Fargate" ] 32 | 33 | EC2: !Equals [ !Ref LaunchType, "EC2" ] 34 | 35 | 36 | Resources: 37 | TaskExecutionRole: 38 | Type: AWS::IAM::Role 39 | Properties: 40 | Path: / 41 | AssumeRolePolicyDocument: 42 | Version: 2012-10-17 43 | Statement: 44 | - Action: sts:AssumeRole 45 | Effect: Allow 46 | Principal: 47 | Service: ecs-tasks.amazonaws.com 48 | ManagedPolicyArns: 49 | - arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy 50 | 51 | LogGroup: 52 | Type: AWS::Logs::LogGroup 53 | Properties: 54 | LogGroupName: !Sub /ecs/${AWS::StackName} 55 | 56 | FargateService: 57 | Type: AWS::ECS::Service 58 | Condition: Fargate 59 | Properties: 60 | Cluster: !Ref Cluster 61 | DesiredCount: !Ref DesiredCount 62 | TaskDefinition: !Ref TaskDefinition 63 | LaunchType: FARGATE 64 | NetworkConfiguration: 65 | AwsvpcConfiguration: 66 | AssignPublicIp: ENABLED 67 | SecurityGroups: 68 | - !Ref SourceSecurityGroup 69 | Subnets: !Ref Subnets 70 | LoadBalancers: 71 | - ContainerName: simple-app 72 | ContainerPort: 80 73 | TargetGroupArn: !Ref TargetGroup 74 | 75 | EC2Service: 76 | Type: AWS::ECS::Service 77 | Condition: EC2 78 | Properties: 79 | Cluster: !Ref Cluster 80 | DesiredCount: !Ref DesiredCount 81 | TaskDefinition: !Ref TaskDefinition 82 | LaunchType: EC2 83 | LoadBalancers: 84 | - ContainerName: simple-app 85 | ContainerPort: 80 86 | TargetGroupArn: !Ref TargetGroup 87 | 88 | TaskDefinition: 89 | Type: AWS::ECS::TaskDefinition 90 | Properties: 91 | Family: !Sub ${AWS::StackName}-simple-app 92 | RequiresCompatibilities: 93 | - !If [ Fargate, "FARGATE", "EC2" ] 94 | Memory: 512 95 | Cpu: 256 96 | NetworkMode: !If [ Fargate, "awsvpc", "bridge" ] 97 | ExecutionRoleArn: !Ref TaskExecutionRole 98 | ContainerDefinitions: 99 | - Name: simple-app 100 | Image: amazon/amazon-ecs-sample 101 | EntryPoint: 102 | - /usr/sbin/apache2 103 | - -D 104 | - FOREGROUND 105 | Essential: true 106 | Memory: 256 107 | MountPoints: 108 | - SourceVolume: my-vol 109 | ContainerPath: /var/www/my-vol 110 | PortMappings: 111 | - ContainerPort: 80 112 | LogConfiguration: 113 | LogDriver: awslogs 114 | Options: 115 | awslogs-region: !Ref AWS::Region 116 | awslogs-group: !Ref LogGroup 117 | awslogs-stream-prefix: !Ref AWS::StackName 118 | - Name: busybox 119 | Image: busybox 120 | EntryPoint: 121 | - sh 122 | - -c 123 | Essential: true 124 | Memory: 256 125 | VolumesFrom: 126 | - SourceContainer: simple-app 127 | Command: 128 | - /bin/sh -c "while true; do /bin/date > /var/www/my-vol/date; sleep 1; done" 129 | Volumes: 130 | - Name: my-vol 131 | 132 | 133 | Outputs: 134 | Service: 135 | Value: !If [ Fargate, !Ref FargateService, !Ref EC2Service ] 136 | -------------------------------------------------------------------------------- /ecs-refarch-continuous-deployment.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: 2010-09-09 3 | 4 | 5 | Description: > 6 | This template shows how to use AWS CodePipeline and AWS CodeBuild to build an 7 | automated continuous deployment pipeline to Amazon Elastic Container Service 8 | (Amazon ECS) using clusters powered by AWS Fargate or Amazon Elastic Compute 9 | Cloud (Amazon EC2). 10 | 11 | 12 | Parameters: 13 | LaunchType: 14 | Type: String 15 | Default: Fargate 16 | AllowedValues: 17 | - Fargate 18 | - EC2 19 | Description: > 20 | The launch type for your service. Selecting EC2 will create an Auto 21 | Scaling group of t2.micro instances for your cluster. See 22 | https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_types.html 23 | to learn more about launch types. 24 | 25 | GitHubUser: 26 | Type: String 27 | Description: Your username on GitHub. 28 | 29 | GitHubRepo: 30 | Type: String 31 | Default: ecs-demo-php-simple-app 32 | Description: The repo name of the sample service. 33 | 34 | GitHubBranch: 35 | Type: String 36 | Default: master 37 | Description: The branch of the repo to continuously deploy. 38 | 39 | GitHubToken: 40 | Type: String 41 | NoEcho: true 42 | Description: > 43 | Token for the user specified above. (https://github.com/settings/tokens) 44 | 45 | TemplateBucket: 46 | Type: String 47 | Default: ecs-refarch-continuous-deployment 48 | Description: > 49 | The S3 bucket from which to fetch the templates used by this stack. 50 | 51 | 52 | Metadata: 53 | AWS::CloudFormation::Interface: 54 | ParameterLabels: 55 | GitHubUser: 56 | default: "User" 57 | GitHubRepo: 58 | default: "Repo" 59 | GitHubBranch: 60 | default: "Branch" 61 | GitHubToken: 62 | default: "Personal Access Token" 63 | LaunchType: 64 | default: "Launch Type" 65 | ParameterGroups: 66 | - Label: 67 | default: Cluster Configuration 68 | Parameters: 69 | - LaunchType 70 | - Label: 71 | default: GitHub Configuration 72 | Parameters: 73 | - GitHubRepo 74 | - GitHubBranch 75 | - GitHubUser 76 | - GitHubToken 77 | - Label: 78 | default: Stack Configuration 79 | Parameters: 80 | - TemplateBucket 81 | 82 | 83 | Resources: 84 | Cluster: 85 | Type: AWS::CloudFormation::Stack 86 | Properties: 87 | TemplateURL: !Sub "https://s3.amazonaws.com/${TemplateBucket}/templates/ecs-cluster.yaml" 88 | Parameters: 89 | LaunchType: !Ref LaunchType 90 | SourceSecurityGroup: !GetAtt LoadBalancer.Outputs.SecurityGroup 91 | Subnets: !GetAtt VPC.Outputs.Subnets 92 | VpcId: !GetAtt VPC.Outputs.VpcId 93 | 94 | DeploymentPipeline: 95 | Type: AWS::CloudFormation::Stack 96 | Properties: 97 | TemplateURL: !Sub "https://s3.amazonaws.com/${TemplateBucket}/templates/deployment-pipeline.yaml" 98 | Parameters: 99 | Cluster: !GetAtt Cluster.Outputs.ClusterName 100 | Service: !GetAtt Service.Outputs.Service 101 | GitHubUser: !Ref GitHubUser 102 | GitHubToken: !Ref GitHubToken 103 | GitHubRepo: !Ref GitHubRepo 104 | GitHubBranch: !Ref GitHubBranch 105 | 106 | LoadBalancer: 107 | Type: AWS::CloudFormation::Stack 108 | Properties: 109 | TemplateURL: !Sub "https://s3.amazonaws.com/${TemplateBucket}/templates/load-balancer.yaml" 110 | Parameters: 111 | LaunchType: !Ref LaunchType 112 | Subnets: !GetAtt VPC.Outputs.Subnets 113 | VpcId: !GetAtt VPC.Outputs.VpcId 114 | 115 | VPC: 116 | Type: AWS::CloudFormation::Stack 117 | Properties: 118 | TemplateURL: !Sub "https://s3.amazonaws.com/${TemplateBucket}/templates/vpc.yaml" 119 | Parameters: 120 | Name: !Ref AWS::StackName 121 | VpcCIDR: 10.215.0.0/16 122 | Subnet1CIDR: 10.215.10.0/24 123 | Subnet2CIDR: 10.215.20.0/24 124 | 125 | Service: 126 | Type: AWS::CloudFormation::Stack 127 | Properties: 128 | TemplateURL: !Sub "https://s3.amazonaws.com/${TemplateBucket}/templates/service.yaml" 129 | Parameters: 130 | Cluster: !GetAtt Cluster.Outputs.ClusterName 131 | LaunchType: !Ref LaunchType 132 | TargetGroup: !GetAtt LoadBalancer.Outputs.TargetGroup 133 | SourceSecurityGroup: !GetAtt LoadBalancer.Outputs.SecurityGroup 134 | Subnets: !GetAtt VPC.Outputs.Subnets 135 | 136 | 137 | Outputs: 138 | ServiceUrl: 139 | Description: The sample service that is being continuously deployed. 140 | Value: !GetAtt LoadBalancer.Outputs.ServiceUrl 141 | 142 | PipelineUrl: 143 | Description: The continuous deployment pipeline in the AWS Management Console. 144 | Value: !GetAtt DeploymentPipeline.Outputs.PipelineUrl 145 | -------------------------------------------------------------------------------- /templates/ecs-cluster.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: 2010-09-09 3 | 4 | 5 | Parameters: 6 | LaunchType: 7 | Type: String 8 | Default: Fargate 9 | AllowedValues: 10 | - Fargate 11 | - EC2 12 | 13 | InstanceType: 14 | Type: String 15 | Default: t2.micro 16 | 17 | ClusterSize: 18 | Type: Number 19 | Default: 2 20 | 21 | Subnets: 22 | Type: List 23 | 24 | SourceSecurityGroup: 25 | Type: AWS::EC2::SecurityGroup::Id 26 | 27 | VpcId: 28 | Type: AWS::EC2::VPC::Id 29 | 30 | 31 | Conditions: 32 | EC2: !Equals [ !Ref LaunchType, "EC2" ] 33 | 34 | 35 | Mappings: 36 | AWSRegionToAMI: 37 | ap-south-1: 38 | AMI: ami-00491f6f 39 | eu-west-3: 40 | AMI: ami-9aef59e7 41 | eu-west-2: 42 | AMI: ami-67cbd003 43 | eu-west-1: 44 | AMI: ami-1d46df64 45 | ap-northeast-2: 46 | AMI: ami-c212b2ac 47 | ap-northeast-1: 48 | AMI: ami-872c4ae1 49 | sa-east-1: 50 | AMI: ami-af521fc3 51 | ca-central-1: 52 | AMI: ami-435bde27 53 | ap-southeast-1: 54 | AMI: ami-910d72ed 55 | ap-southeast-2: 56 | AMI: ami-58bb443a 57 | eu-central-1: 58 | AMI: ami-509a053f 59 | us-east-1: 60 | AMI: ami-28456852 61 | us-east-2: 62 | AMI: ami-ce1c36ab 63 | us-west-1: 64 | AMI: ami-74262414 65 | us-west-2: 66 | AMI: ami-decc7fa6 67 | 68 | 69 | Resources: 70 | ECSRole: 71 | Type: AWS::IAM::Role 72 | Condition: EC2 73 | Properties: 74 | Path: / 75 | AssumeRolePolicyDocument: 76 | Statement: 77 | - Action: sts:AssumeRole 78 | Effect: Allow 79 | Principal: 80 | Service: ec2.amazonaws.com 81 | ManagedPolicyArns: 82 | - arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role 83 | 84 | InstanceProfile: 85 | Type: AWS::IAM::InstanceProfile 86 | Condition: EC2 87 | Properties: 88 | Path: / 89 | Roles: 90 | - !Ref ECSRole 91 | 92 | SecurityGroup: 93 | Type: "AWS::EC2::SecurityGroup" 94 | Condition: EC2 95 | Properties: 96 | GroupDescription: !Sub ${AWS::StackName}-hosts 97 | SecurityGroupIngress: 98 | - SourceSecurityGroupId: !Ref SourceSecurityGroup 99 | IpProtocol: -1 100 | VpcId: !Ref VpcId 101 | 102 | Cluster: 103 | Type: AWS::ECS::Cluster 104 | Properties: 105 | ClusterName: !Ref AWS::StackName 106 | 107 | AutoScalingGroup: 108 | Type: AWS::AutoScaling::AutoScalingGroup 109 | Condition: EC2 110 | Properties: 111 | VPCZoneIdentifier: !Ref Subnets 112 | LaunchConfigurationName: !Ref LaunchConfiguration 113 | MinSize: !Ref ClusterSize 114 | MaxSize: !Ref ClusterSize 115 | DesiredCapacity: !Ref ClusterSize 116 | Tags: 117 | - Key: Name 118 | Value: !Sub ${AWS::StackName} - ECS Host 119 | PropagateAtLaunch: true 120 | CreationPolicy: 121 | ResourceSignal: 122 | Timeout: PT15M 123 | UpdatePolicy: 124 | AutoScalingRollingUpdate: 125 | MinInstancesInService: 1 126 | MaxBatchSize: 1 127 | PauseTime: PT15M 128 | WaitOnResourceSignals: true 129 | 130 | LaunchConfiguration: 131 | Type: AWS::AutoScaling::LaunchConfiguration 132 | Condition: EC2 133 | Metadata: 134 | AWS::CloudFormation::Init: 135 | config: 136 | commands: 137 | 01_add_instance_to_cluster: 138 | command: !Sub echo ECS_CLUSTER=${Cluster} > /etc/ecs/ecs.config 139 | files: 140 | "/etc/cfn/cfn-hup.conf": 141 | mode: 000400 142 | owner: root 143 | group: root 144 | content: !Sub | 145 | [main] 146 | stack=${AWS::StackId} 147 | region=${AWS::Region} 148 | "/etc/cfn/hooks.d/cfn-auto-reloader.conf": 149 | content: !Sub | 150 | [cfn-auto-reloader-hook] 151 | triggers=post.update 152 | path=Resources.ContainerInstances.Metadata.AWS::CloudFormation::Init 153 | action=/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration 154 | services: 155 | sysvinit: 156 | cfn-hup: 157 | enabled: true 158 | ensureRunning: true 159 | files: 160 | - /etc/cfn/cfn-hup.conf 161 | - /etc/cfn/hooks.d/cfn-auto-reloader.conf 162 | Properties: 163 | ImageId: !FindInMap [ AWSRegionToAMI, !Ref "AWS::Region", AMI ] 164 | InstanceType: !Ref InstanceType 165 | IamInstanceProfile: !Ref InstanceProfile 166 | SecurityGroups: 167 | - !Ref SecurityGroup 168 | UserData: 169 | "Fn::Base64": !Sub | 170 | #!/bin/bash 171 | yum install -y aws-cfn-bootstrap 172 | /opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource LaunchConfiguration 173 | /opt/aws/bin/cfn-signal -e $? --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup 174 | 175 | 176 | Outputs: 177 | ClusterName: 178 | Value: !Ref Cluster 179 | -------------------------------------------------------------------------------- /templates/deployment-pipeline.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | AWSTemplateFormatVersion: 2010-09-09 3 | 4 | 5 | Parameters: 6 | GitHubRepo: 7 | Type: String 8 | 9 | GitHubBranch: 10 | Type: String 11 | 12 | GitHubToken: 13 | Type: String 14 | NoEcho: true 15 | 16 | GitHubUser: 17 | Type: String 18 | 19 | Cluster: 20 | Type: String 21 | 22 | Service: 23 | Type: String 24 | 25 | 26 | Resources: 27 | Repository: 28 | Type: AWS::ECR::Repository 29 | DeletionPolicy: Retain 30 | 31 | CodeBuildServiceRole: 32 | Type: AWS::IAM::Role 33 | Properties: 34 | Path: / 35 | AssumeRolePolicyDocument: 36 | Version: 2012-10-17 37 | Statement: 38 | - Effect: Allow 39 | Principal: 40 | Service: codebuild.amazonaws.com 41 | Action: sts:AssumeRole 42 | Policies: 43 | - PolicyName: root 44 | PolicyDocument: 45 | Version: 2012-10-17 46 | Statement: 47 | - Resource: "*" 48 | Effect: Allow 49 | Action: 50 | - logs:CreateLogGroup 51 | - logs:CreateLogStream 52 | - logs:PutLogEvents 53 | - ecr:GetAuthorizationToken 54 | - Resource: !Sub arn:aws:s3:::${ArtifactBucket}/* 55 | Effect: Allow 56 | Action: 57 | - s3:GetObject 58 | - s3:PutObject 59 | - s3:GetObjectVersion 60 | - Resource: !Sub arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/${Repository} 61 | Effect: Allow 62 | Action: 63 | - ecr:GetDownloadUrlForLayer 64 | - ecr:BatchGetImage 65 | - ecr:BatchCheckLayerAvailability 66 | - ecr:PutImage 67 | - ecr:InitiateLayerUpload 68 | - ecr:UploadLayerPart 69 | - ecr:CompleteLayerUpload 70 | 71 | CodePipelineServiceRole: 72 | Type: AWS::IAM::Role 73 | Properties: 74 | Path: / 75 | AssumeRolePolicyDocument: 76 | Version: 2012-10-17 77 | Statement: 78 | - Effect: Allow 79 | Principal: 80 | Service: codepipeline.amazonaws.com 81 | Action: sts:AssumeRole 82 | Policies: 83 | - PolicyName: root 84 | PolicyDocument: 85 | Version: 2012-10-17 86 | Statement: 87 | - Resource: 88 | - !Sub arn:aws:s3:::${ArtifactBucket}/* 89 | Effect: Allow 90 | Action: 91 | - s3:PutObject 92 | - s3:GetObject 93 | - s3:GetObjectVersion 94 | - s3:GetBucketVersioning 95 | - Resource: "*" 96 | Effect: Allow 97 | Action: 98 | - ecs:DescribeServices 99 | - ecs:DescribeTaskDefinition 100 | - ecs:DescribeTasks 101 | - ecs:ListTasks 102 | - ecs:RegisterTaskDefinition 103 | - ecs:UpdateService 104 | - codebuild:StartBuild 105 | - codebuild:BatchGetBuilds 106 | - iam:PassRole 107 | 108 | ArtifactBucket: 109 | Type: AWS::S3::Bucket 110 | DeletionPolicy: Retain 111 | 112 | CodeBuildProject: 113 | Type: AWS::CodeBuild::Project 114 | Properties: 115 | Artifacts: 116 | Type: CODEPIPELINE 117 | Source: 118 | Type: CODEPIPELINE 119 | BuildSpec: | 120 | version: 0.2 121 | phases: 122 | pre_build: 123 | commands: 124 | - $(aws ecr get-login --no-include-email) 125 | - TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)" 126 | - IMAGE_URI="${REPOSITORY_URI}:${TAG}" 127 | build: 128 | commands: 129 | - docker build --tag "$IMAGE_URI" . 130 | post_build: 131 | commands: 132 | - docker push "$IMAGE_URI" 133 | - printf '[{"name":"simple-app","imageUri":"%s"}]' "$IMAGE_URI" > images.json 134 | artifacts: 135 | files: images.json 136 | Environment: 137 | ComputeType: BUILD_GENERAL1_SMALL 138 | Image: aws/codebuild/docker:17.09.0 139 | Type: LINUX_CONTAINER 140 | EnvironmentVariables: 141 | - Name: AWS_DEFAULT_REGION 142 | Value: !Ref AWS::Region 143 | - Name: REPOSITORY_URI 144 | Value: !Sub ${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/${Repository} 145 | Name: !Ref AWS::StackName 146 | ServiceRole: !Ref CodeBuildServiceRole 147 | 148 | Pipeline: 149 | Type: AWS::CodePipeline::Pipeline 150 | Properties: 151 | RoleArn: !GetAtt CodePipelineServiceRole.Arn 152 | ArtifactStore: 153 | Type: S3 154 | Location: !Ref ArtifactBucket 155 | Stages: 156 | - Name: Source 157 | Actions: 158 | - Name: App 159 | ActionTypeId: 160 | Category: Source 161 | Owner: ThirdParty 162 | Version: 1 163 | Provider: GitHub 164 | Configuration: 165 | Owner: !Ref GitHubUser 166 | Repo: !Ref GitHubRepo 167 | Branch: !Ref GitHubBranch 168 | OAuthToken: !Ref GitHubToken 169 | OutputArtifacts: 170 | - Name: App 171 | RunOrder: 1 172 | - Name: Build 173 | Actions: 174 | - Name: Build 175 | ActionTypeId: 176 | Category: Build 177 | Owner: AWS 178 | Version: 1 179 | Provider: CodeBuild 180 | Configuration: 181 | ProjectName: !Ref CodeBuildProject 182 | InputArtifacts: 183 | - Name: App 184 | OutputArtifacts: 185 | - Name: BuildOutput 186 | RunOrder: 1 187 | - Name: Deploy 188 | Actions: 189 | - Name: Deploy 190 | ActionTypeId: 191 | Category: Deploy 192 | Owner: AWS 193 | Version: 1 194 | Provider: ECS 195 | Configuration: 196 | ClusterName: !Ref Cluster 197 | ServiceName: !Ref Service 198 | FileName: images.json 199 | InputArtifacts: 200 | - Name: BuildOutput 201 | RunOrder: 1 202 | 203 | 204 | Outputs: 205 | PipelineUrl: 206 | Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline} 207 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ECS Reference Architecture: Continuous Deployment 2 | 3 | The ECS Continuous Deployment reference architecture demonstrates how to achieve 4 | [continuous deployment][continuous-deployment] of an application to Amazon 5 | Elastic Container Service (Amazon ECS) using AWS CodePipeline and AWS 6 | CodeBuild. With continuous deployment, software revisions are deployed to a 7 | production environment automatically without explicit approval from a developer, 8 | making the entire software release process automated. 9 | 10 | Launching this AWS CloudFormation stack provisions a continuous deployment 11 | process that uses AWS CodePipeline to monitor a GitHub repository for new 12 | commits and AWS CodeBuild to create a new Docker container image and to push it 13 | into Amazon Elastic Container Registry (Amazon ECR). 14 | 15 | When creating this stack, you can opt to deploy the service onto [AWS 16 | Fargate][fargate] or [Amazon EC2][ec2]. AWS Fargate allows you to run containers 17 | without managing clusters or services. If you choose Amazon EC2, an Auto Scaling 18 | group of t2.micro instances will be created to host your service. 19 | 20 | [![](images/architecture.png)][architecture] 21 | 22 | ## Running the example 23 | 24 | #### 1. Fork the GitHub repository 25 | 26 | [Fork](https://help.github.com/articles/fork-a-repo/) the [Amazon ECS sample 27 | app](https://github.com/awslabs/ecs-demo-php-simple-app) GitHub repository into 28 | your GitHub account. 29 | 30 | From your terminal application, execute the following command (make sure to 31 | replace `` with your actual GitHub username): 32 | 33 | ```console 34 | git clone https://github.com//ecs-demo-php-simple-app 35 | ``` 36 | 37 | This creates a directory named `ecs-demo-php-simple-app` in your current 38 | directory, which contains the code for the Amazon ECS sample app. 39 | 40 | #### 2. Create the CloudFormation stack 41 | 42 | Deploy | Region Name | Region | Launch Types 43 | :---: | ------------ | ------------- | ------------- 44 | [🚀][us-east-1] | US East (N. Virginia) | us-east-1 | Fargate, EC2 45 | [🚀][us-east-2] | US East (Ohio) | us-east-2 | EC2 46 | [🚀][us-west-1] | US West (N. California) | us-west-1 | EC2 47 | [🚀][us-west-2] | US West (Oregon) | us-west-2 | EC2 48 | [🚀][eu-west-1] | EU (Ireland) | eu-west-1 | EC2 49 | [🚀][eu-west-2] | EU (London) | eu-west-2 | EC2 50 | [🚀][eu-central-1] | EU (Frankfurt) | eu-central-1 | EC2 51 | [🚀][ap-southeast-1] | Asia Pacific (Singapore) | ap-southeast-1 | EC2 52 | [🚀][ap-southeast-2] | Asia Pacific (Sydney) | ap-southeast-2 | EC2 53 | [🚀][ap-northeast-1] | Asia Pacific (Tokyo) | ap-northeast-1 | EC2 54 | [🚀][ap-northeast-2] | Asia Pacific (Seoul) | ap-northeast-2 | EC2 55 | [🚀][ca-central-1] | Canada (Central) | ca-central-1 | EC2 56 | 57 | This reference architecture can only be deployed to Regions which have all 58 | necessary services available. See the [Region 59 | Table](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) 60 | for information about service availability. 61 | 62 | The CloudFormation template requires the following parameters: 63 | 64 | - Cluster Configuration 65 | - **Launch Type**: Deploy the service using either AWS Fargate or Amazon EC2. 66 | Selecting EC2 will create an Auto Scaling group of t2.micro instances for 67 | your cluster. See the [documentation][launch-types] to learn more about 68 | launch types. 69 | 70 | - GitHub Configuration 71 | - **Repo**: The repo name of the sample service. 72 | - **Branch**: The branch of the repo to deploy continuously. 73 | - **User**: Your username on GitHub. 74 | - **Personal Access Token**: Token for the user specified above. 75 | ([https://github.com/settings/tokens](https://github.com/settings/tokens)) 76 | 77 | The CloudFormation stack provides the following output: 78 | 79 | - **ServiceUrl**: The sample service that is being continuously deployed. 80 | - **PipelineUrl**: The continuous deployment pipeline in the AWS Management 81 | Console. 82 | 83 | ### Testing the example 84 | 85 | After the CloudFormation stack is created, the latest commit to the GitHub 86 | repository is run through the pipeline and deployed to ECS. Open the 87 | **PipelineUrl** to watch the first revision run through the CodePipeline 88 | pipeline. After the deploy step turns green, open the URL from **ServiceUrl** 89 | which loads a page similar to this: 90 | 91 | ![ECS sample app](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/images/simple-php-app.png) 92 | 93 | To test continuous deployment, make a change to src/index.php in the 94 | ecs-demo-php-simple-app repository and push it to GitHub. CodePipeline detects 95 | the change, builds the new application, and deploys it to your cluster 96 | automatically. After the pipeline finishes deploying the revision, reload the 97 | page to see the changes made. 98 | 99 | ### Cleaning up the example resources 100 | 101 | To remove all resources created by this example, do the following: 102 | 103 | 1. Delete the main CloudFormation stack which deletes the substacks and resources. 104 | 1. Manually delete resources which may contain content: 105 | 106 | - S3 Bucket: ArtifactBucket 107 | - ECR Repository: Repository 108 | 109 | ## CloudFormation template resources 110 | 111 | The following sections explains all of the resources created by the 112 | CloudFormation template provided with this example. 113 | 114 | #### [DeploymentPipeline](templates/deployment-pipeline.yaml) 115 | 116 | Resources that compose the deployment pipeline include the CodeBuild project, 117 | the CodePipeline pipeline, an S3 bucket for deployment artifacts, and all 118 | necessary IAM roles used by those services. 119 | 120 | #### [Service](templates/service.yaml) 121 | 122 | An ECS task definition, service, IAM role, and ECR repository for the sample 123 | application. This template is used by the CodePipeline pipeline to deploy the 124 | sample service continuously. 125 | 126 | #### [Cluster](templates/ecs-cluster.yaml) 127 | 128 | An ECS cluster optionally backed by an Auto Scaling group of EC2 instances 129 | running the Amazon ECS-optimized AMI for the EC2 launch type. 130 | 131 | #### [Load Balancer](templates/load-balancer.yaml) 132 | 133 | An Application Load Balancer to be used for traffic to the sample application. 134 | 135 | #### [VPC](templates/vpc.yaml) 136 | 137 | A VPC with two public subnets on two separate Availability Zones, an internet 138 | gateway, and a route table with a default route to the public internet. 139 | 140 | ## License 141 | 142 | This reference architecture sample is [licensed][license] under Apache 2.0. 143 | 144 | [continuous-deployment]: https://aws.amazon.com/devops/continuous-delivery/ 145 | [architecture]: images/architecture.pdf 146 | [license]: LICENSE 147 | [fargate]: https://aws.amazon.com/fargate/ 148 | [ec2]: https://aws.amazon.com/ec2/ 149 | [launch-types]: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch_types.html 150 | [us-east-1]: https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=Fargate 151 | [us-east-2]: https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 152 | [us-west-1]: https://console.aws.amazon.com/cloudformation/home?region=us-west-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 153 | [us-west-2]: https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 154 | [eu-west-1]: https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 155 | [eu-west-2]: https://console.aws.amazon.com/cloudformation/home?region=eu-west-2#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 156 | [eu-central-1]: https://console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 157 | [ap-southeast-1]: https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 158 | [ap-southeast-2]: https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-2#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 159 | [ap-northeast-1]: https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 160 | [ap-northeast-2]: https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 161 | [ca-central-1]: https://console.aws.amazon.com/cloudformation/home?region=ca-central-1#/stacks/create/review?stackName=ECS-ContinuousDeployment&templateURL=https://s3.amazonaws.com/ecs-refarch-continuous-deployment/ecs-refarch-continuous-deployment.yaml¶m_LaunchType=EC2 162 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 Amazon Web Services 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------