Miscellaneous notes that I keep needing to refer to.
Read a file in S3 from the command line
If you want to, say, look at the numbof lines in a file, run:
aws s3 cp s3://BUCKET/PATH - | wc -l
Note the critical hypen.
Avoid Pagination
The --no-cli-pager switch is the daddy here. If I want to list all my RDS databases in a script, I don't want them to be paginated nor truncated, so run:
aws rds describe-db-instances --no-cli-pager
Logging
Run something like this to get the logs:
aws logs tail YOUR_LOG_GROUP_NAME --since 5d
where YOUR_LOG_GROUP_NAME is in your container_definitions/options/awslogs-group of resource "aws_ecs_task_definition" "backend_task" if you're using Terraform.
The 5d is the last 5 days, but it could be, sah 1h (the last hour) or --follow if you want to tail it.
Caveat
Beware that you configure the health check of your services correctly. One of our services was returning an HTTP error 404 for the page the health checker was trying to hit. Everything was fine other than a page was missing. But AWS saw the 404 and kept deciding to kill the service. Oops.
Terraform
This isn't specifically related to AWS but since I use the two together, I'll post here.
Create new workspaces to isolate yourself from breaking other people's work with:
terraform workspace new staging
Bad boys and girls might change the environment by hand. In this case, you have tell Terraform to import it with something like:
terraform import -var-file="vars/production.tfvars" -var="x=y" ... aws_db_subnet_group.my_db my-db
You can see the dependency graph of your infrastructure with:
terraform graph | dot -Tsvg > ~/Pictures/graph.svg
Docker
This has helped me a few times when trying to work out locally why my Docker container does not work when depoyed in ECS. Say your container dies immediately. You can debug (on Ubuntu) the docker daemon itself with:
journalctl -f -u docker.service
Then you can see the IDs of short lived containers and get its logs (see the Docker docs)
No comments:
Post a Comment