queirozsc
8/13/2017 - 6:52 AM

[codedeploy] O AWS CodeDeploy é um serviço que automatiza as implantações de código em qualquer instância, incluindo as do Amazon EC2 e as e

[codedeploy] O AWS CodeDeploy é um serviço que automatiza as implantações de código em qualquer instância, incluindo as do Amazon EC2 e as executadas no local #aws #codedeploy

#Granting permissions for your user account to use AWS CodeDeploy
aws iam attach-user-policy --user-name sergio.queiroz --policy-arn arn:aws:iam::aws:policy/AWSCodeDeployFullAccess
#Deploying your application using CodeDeploy
aws deploy create-deployment --application-name [ApplicationName] --deployment-config-name CodeDeployDefault.OneAtATime --deployment-group-name [DeploymentGroupName] --s3-location bucket=[BucketName],bundleType=zip,key=BuildOutput.zip
#local file: CodeDeployDemo-EC2-Trust.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "ec2.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

#local file: CodeDeployDemo-EC2-Permissions.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:Get*",
        "s3:List*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}

#Creating an instance profile for your EC2 instance(s)
aws iam create-role --role-name CodeDeployDemo-EC2-Instance-Profile --assume-role-policy-document file://CodeDeployDemo-EC2-Trust.json
aws iam put-role-policy --role-name CodeDeployDemo-EC2-Instance-Profile --policy-name CodeDeployDemo-EC2-Permissions --policy-document file://CodeDeployDemo-EC2-Permissions.json
aws iam create-instance-profile --instance-profile-name CodeDeployDemo-EC2-Instance-Profile
aws iam add-role-to-instance-profile --instance-profile-name CodeDeployDemo-EC2-Instance-Profile --role-name CodeDeployDemo-EC2-Instance-Profile
# Creating an application in CodeDeploy
aws deploy create-application --application-name [ApplicationName]
#local file: CodeDeployDemo-Trust.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "codedeploy.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

#Creating a service role for the AWS CodeDeploy service
aws iam create-role --role-name CodeDeployServiceRole --assume-role-policy-document file://CodeDeployDemo-Trust.json
aws iam attach-role-policy --role-name CodeDeployServiceRole --policy-arn arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole
#repository file: appspec.yml
version: 0.0
os: windows
files:
  - source: \app.js
    destination: c:\host
  - source: \node_modules
    destination: c:\host\node_modules

#Creating a deployment group in CodeDeploy
#Tag the instance with the name-value pair: (CodeDeploy, Yes). This is important because it will tell CodeDeploy what instances to deploy to
aws deploy create-deployment-group --application-name [ApplicationName] --deployment-group-name [DeploymentGroupName] --deployment-config-name CodeDeployDefault.OneAtATime --ec2-tag-filters Key=CodeDeploy,Value=Yes,Type=KEY_AND_VALUE --service-role-arn [ServiceRoleARN]