aws ssm ec2
Tags: Github actions, ssh connection, AWS SSM, EC2, IAM permission
pain point
- Github actions ssh connection failed with timeout(used apple boy)
first approach
- replace apple boy to another found in marketplace, RESULT: failed
- ask deep seek with other approach
how to fix
- use aws ssm to send command to execute in ec2
- update ecr and use the githubs sha to pull the tag image in ec2, aws ssm send command targeting with ec2 instance id.
- fail with syntaxes a few times. at the end, found out it is the EC2 IAM permission related issue.
- attach the ecr policy for ec2 IAM.
step by step
- update dev branch
- ci will be run
- create pr to merge dev to main
- pr will be merged
- deploy will be run
- check out codebase and secrets
- login to aws ecr
- build, tag, push the image from Dckerfile
- aws ssm send command to EC2 for docker
- in ec2, shell script will be run.
- pull new image with the tag provided, stop running container remove running container
- run new container on new image.
final thoughts
- ssh connection is useful and no cost, but not running in github actions.
- use ssm is simple approach but fast and reliable.
- guess there are more ways to connect to ec2, will find out like today i did.