Script for automating the process of creating a ec2 instance with ecs container to run a small task on different instances
-
Add the following configuration details in
conf
:ACCESS_KEY
andSECRET_KEY
: AWS credentialsKEY
: name of the pem fileREGION
: ec2 instance regionINSTANCE_TYPE
: instance flavor (eg. t2.small, t3.medium, etc.)LAUNCH_TYPE
: EC2 or FargateVPC
andSUBNET
for the ec2 instance
-
Run
parsers.py
python3 parsers.py --aws <instance_type> --docker <docker_image> --entrypoint_args <args for docker entrypoint>
-
Voilà! an ECS cluster is created using a randomized cluster name. This cluster creates a ec2 instance of the specified instance flavour. A docker is deployed on the instance using the docker compose file generated by
parsers.py
. -
After 60 secs, the instance is terminated and the cluster is deleted. If you want to delay the process of cleanup you can increase the sleep time in
create_ec2_instance.sh
or you can comment out thecleanup
function in case you don't want to run the cleanup process.