Code Deploy
Code Deploy
CREATE AN APPLICATION
To Create an Application.
Go to Code-deploy Console.
Click create application.
Type Application name.
Type Deployment group name.
Select Deployment type (in-place or blue/green).
Select environment (asg or instances or on-permises).
Choose instances to this deployment group.
Select Deployment configuration(all, once, half).
Select Service Role.
Click Create Application.
After creating application, click on the application name, you will see deployment
groups, revisions.
To deploy latest application content,
Select deployment group.
Click Actions.
Click deploy new version.
In deployment page,
Select your application.
Select your deployment group.
Select repo type(s3, git).
If you select S3, type the url of your project dir.
If you select GIT, paste the git repo url in the field and paste commit ID to take code.
Click, Create.
To deploy a new version again,
Click on Create Deployment.
Select your application.
Select deployment group.
Type commit ID and git repo.
Click Create.
It will download the source bundle from git and install latest version based on the order
in appspec.yml file and once it successed try browse the page with instance public IP
(or) domain name. You will see latest version of your code.
You can create multiple deployment groups with instances for different scenarios like
test and production.
So that, You can test your latest code in test deployment group and once it successed
you can deploy it in production deployement group.
You can see all your deployed versions in the application page. For every deployment,
you will get an deployment ID. With this ID, you can see all the content and logs.
The deployment data will be stored in their respective instance along with the
deployment ID. (/opt/codedeploy-agent/deployment-root//deployment-ID).
CODE-DEPLOY LOGS
Code-deploy logs are stored in the respective instances within the deployment ID
directories.
/opt/codedeploy-agent/deployment-root/deployment-logs/ = It will store all deployment
logs individually along with its deployment ID.
/var/log/aws/codedeploy-agent/codedeploy-agent.log = It will store all agent logs here.
You can use cloudwatch logs to monitor code-deploy logs in cloud watch console by
installing the cloud watch logs agent.
You have to specify the logs path and instance ID in /etc/awslogs/awslogs.conf file and it
will push the logs to cloud watch console.
MONITORING
There are several aws monitoring tools to monitor code-deploy (cloud watch logs,
events, cloud trail and sns).
Cloud Watch Logs = It will push application logs to aws console. We have to install cloud
watch logs agent in every instance and configure our application in awslogs.conf file and
it will show our application logs in cloud watch console.
Cloud Trail = It will capture all API calls made by users along with their ACC ID, source ip,
what request made, who and when it happened. You can create a trail and it will store
all logs in S3 bucket you specified. It will show logs in cloud trail console.
SNS = You can create triggers for code-deploy along with SNS notifications. So,
whenever a trigger is happened in a code deployement group, an sms (or) email will
come the reciepents who are in the sns topic.
You can create triggers for deployments and for instances states. First, you have to
create an SNS topic with recipients to get notified.
Before you use sns triggers, you have to give access to code-deploy to use sns. For that
we need to add sns policy to code-deploy service role.
Go to code-deploy service role,
Click incline policies,
Select custom policy, Type policy name (snspublish),
Copy this content in policy area, click validate policy and click apply policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "*"
}
]
}
Now, you can use sns triggers for code-deploy.
To create Triggers,
Go to deployement group page,
Click create trigger,
Type a trigger name,
Select events (deployments (fail, pass, stops etc) or (instances (starts, fails etc)),
Select sns topic, click create.