AWS CLI get status of deployment after deploying to elastic beanstalk - amazon-web-services

The last line of my deployment task using the AWS CLI is
aws elasticbeanstalk update-environment --application-name DevApi --environment-name Dev --version-label v2
How can I check that the deployment of v2 was successful? At the moment I have another browser window open console.aws.amazon.com/elasticbeanstalk/ and check there. But there has to be a better way to automate it as part of my deployment by adding another step (cli command?) so I only need to check the deployment output?
EDIT: I should also mention I am running a Windows Elastic Beanstalk instance.

One way I can think of is to check the EBS Health Reports.
If you are using Basic Monitoring, use the below cli:
aws elasticbeanstalk describe-environments --application-name DevApi --environment-name Dev --query 'Environments[*].{Status: Status,Health: Health} --output json'
Sample output:
[
{
"Status": "Ready",
"Health": "Green"
}
]
For more info about each indicator, read Basic Health Reporting.
If you are using Enhanced Monitoring (for extra cost), then there is an additional parameter available which makes it much more clear.
aws elasticbeanstalk describe-environments --application-name DevApi --environment-name Dev --query 'Environments[*].{Status: Status,Health: Health,HealthStatus: HealthStatus} --output json'
Sample Output:
[
{
"Status": "Ready",
"HealthStatus": "Ok",
"Health": "Green"
}
]
Once the above status is reached, you can conclude the deployment is complete and is healthy.
If the HealthStatus is Info and Health is Green, It indicates An operation is in progress on an instance (or) on several instances in an environment. Example: A new application version is being deployed to running instances.
For more info about each health indicator, do read Enhanced Health reporting.

Related

Failed to create Elasticache redis cluster

I was using the following command to create a Elasticache redis cluster via CLI but it always failed at the end, when I switch to the AWS console I can first see the creating status but after a while it will always fail, is there a way to view the creation logs in AWS console?
aws elasticache create-replication-group --cache-subnet-group group-name --engine redis --engine-version 6.x --security-group-ids security-group-id --num-node-groups 22 --replicas-per-node-group 2 --cache-parameter-group-name parameter-group-name --auto-minor-version-upgrade --replication-group-id some-group-id --replication-group-description 'some description' --cache-node-type cache.r6g.2xlarge --region some-region --automatic-failover-enabled

How to see the deployment progress via aws cli

I created a deployment using AWS cli:
aws deploy create-deployment --application-name systest1 --deployment-group-name TEST --s3-location bucket=artifacts,bundleType=zip,key=APP.zip
and I got the out as
{
"deploymentId": "d-559F8S41O"
}
How can I see the status of the deployment?? I believe
aws deploy get-deployment
will show us the status but it will not show continuous progress. Actually, I am using AWS cli so use don't have to go on AWS console and check the deployment status instead he will get the result on gitlab-ci output only. Any suggestion??
Use the below CLI command to get the status:
aws deploy get-deployment --deployment-id d-52EZVE6PC --query "deploymentInfo.[status, creator]" --output text

Fetch external link of ecs task running from aws cli

How to fetch the external link of aws ecs task running which has the public ip of container instance and port of the task running?
I am managing task/service execution from cli and would like to fetch the external link which is shown in the aws UI from aws cli. I tried describe-tasks command of aws cli but it doesn't return the public IP address of the instance the task is running on.
Is there a way to fetch the same from aws cli?
Thanks in advance!
This is quite the pain in the neck, but it will do what you want:
List your tasks by service name
aws ecs list-tasks --cluster mycluster --service-name my-service-name
Get the details of a task using the task ARN from the above.
aws ecs describe-tasks --cluster mycluster --tasks arn:aws:ecs:us-east-1:999999999999:task/ad0ba3e9-ac3b-4a4c-a1af-de3e06f46dfa
The task description includes two pieces of information you need: the network bindings, which includes the port (look for the one that is mapped to the service port you care about), and the container instance ARN. (NOT the container ARN. Don't make that mistake and be super-confused when the next step fails, like I did). Using the container instance's ARN, get the details of the container instance:
aws ecs describe-container-instances --cluster mycluster --container-instances arn:aws:ecs:us-east-1:999999999999:container-instance/707e5193-51e3-454b-ba09-9745c5d7f527
As part of this description, you should be able to get the EC2 instance ID & query EC2 for more details:
aws ec2 describe-instances --instance-ids i-c91aee40d92c23b3c
^^^^ NOT ECS
The output of this command should include the private IP of the EC2 instance. This IP + previously computed port should correspond to the external link from the web UI.
NOTE: Data has been anonymized, but should still LOOK like what you can expect to see. Also I omitted AWS region and profile params, which I have set to defaults using environment variables.
This should show your Ingress IP address which is a public URL and is typically then mapped to your domain as a Type A record using AWS route53 console so your users can reach same just using your URL domain.com/lalala
aws ecs describe-services --service my-http-service
to discover this command and others generally the aws command line tool is actually very friendly ... just issue
aws help
then view that top level list of available subcommands then drill down by issuing
aws ecs help
and repeat above burrowing deeper into the available commands until you reach what could work ... as in
ecs ecs describe-services help
You can get to the answer you want by running:
aws ecs describe-tasks --cluster foo --tasks 8591006e-6f05-4886-bc4a-58d9063d3852
This will contain the networkBindings section like this:
"networkBindings": [
{
"protocol": "tcp",
"bindIP": "0.0.0.0",
"containerPort": 7000,
"hostPort": 32769
},
{
"protocol": "tcp",
"bindIP": "0.0.0.0",
"containerPort": 7001,
"hostPort": 32768
}
]
Then you're golden!

AWS CodeDeploy - Error deploying - ApplicationDoesNotExistException

I want to deploy a project in AWS using :
$ aws --region eu-central-1 deploy push --application-name DemoApp --s3-location s3://paquirrin-codedeploy/Project1.zip --ignore-hidden-file --source .
But I got this error:
A client error (ApplicationDoesNotExistException) occurred when calling the RegisterApplicationRevision operation: Applications not found for 289558260222
but the application exists:
$ aws deploy list-applications
{
"applications": [
"DemoApp"
]
}
and CodeDeploy agent is running
[root#ip-171-33-54-212 ~]# /etc/init.d/codedeploy-agent status
The AWS CodeDeploy agent is running as PID 2649
but I haven't found the folder deployment-root inside /opt/codedeploy-agent !
You are deploying to region eu-central-1. But you may not be listing the applications in eu-central-1 using following command:
aws deploy list-applications
Instead, use following command to ensure that application exists:
aws deploy list-applications --region eu-central-1

Stop and Start Elastic Beanstalk Services

I wanted to know if there is an option to STOP Amazon Elastic Beanstalk as an atomic unit as I can do with EC2 servers instead of going through each service (e.g. load balancer, EC2..) and STOP (and START) them independently?
The EB command line interface has an eb stop command. Here is a little bit about what the command actually does:
The eb stop command deletes the AWS resources that are running your application (such as the ELB and the EC2 instances). It however leaves behind all of the application versions and configuration settings that you had deployed, so you can quickly get started again. Eb stop is ideal when you are developing and testing your application and don’t need the AWS resources running over night. You can get going again by simply running eb start.
EDIT:
As stated in the below comment, this is no longer a command in the new eb-cli.
If you have a load-balanced environment you can try the following trick
$ aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name my-auto-scaling-group \
--min-size 0 --max-size 0 --desired-capacity 0
It will remove all instances from the environment but won't delete the environment itself. Unfortunately you still will pay for elastic load balancer. But usually EC2 is the most "heavy" part.
Does it work for 0?
yes, it does
$ aws autoscaling describe-auto-scaling-groups --region us-east-1 \
--auto-scaling-group-name ASG_NAME \
--query "AutoScalingGroups[].{DesiredCapacity:DesiredCapacity,MinSize:MinSize,MaxSize:MaxSize}"
[
{
"MinSize": 2,
"MaxSize": 2,
"DesiredCapacity": 2
}
]
$ aws autoscaling update-auto-scaling-group --region us-east-1 \
--auto-scaling-group-name ASG_NAME \
--min-size 0 --max-size 0 --desired-capacity 0
$ aws autoscaling describe-auto-scaling-groups --region us-east-1 \
--auto-scaling-group-name ASG_NAME \
--query "AutoScalingGroups[].{DesiredCapacity:DesiredCapacity,MinSize:MinSize,MaxSize:MaxSize}"
[
{
"MinSize": 0,
"MaxSize": 0,
"DesiredCapacity": 0
}
]
And then you can check environment status
$ eb status -v
Environment details for: test
Application name: TEST
Region: us-east-1
Deployed Version: app-170925_181953
Environment ID: e-1234567890
Platform: arn:aws:elasticbeanstalk:us-east-1::platform/Multi-container Docker running on 64bit Amazon Linux/2.7.4
Tier: WebServer-Standard
CNAME: test.us-east-1.elasticbeanstalk.com
Updated: 2017-09-25 15:23:22.980000+00:00
Status: Ready
Health: Grey
Running instances: 0
In the beanstalk webconsole you will see the following message
INFO Environment health has transitioned from Ok to No Data.
There are no instances. Auto Scaling group desired capacity is set to zero.
eb stop is deprecated. I also had the same problem and the only solution I could come up with was to backup the environment and then restore it.
Here's a blog post in which I'm explaining it:
http://pminkov.github.io/blog/how-to-shut-down-and-restore-an-elastic-beanstalk-environment.html