As a first step, download a CloudFormation stack that will deploy for you the following resources:
After downloading the template, open the CloudFormation console and on the top-right corner of the screen, click on Create stack. Follow the following steps:
It is important that you use MonteCarloWithBatch as the stack name, as later we will use that value to retrieve some outputs programmatically.
The stack creation process will begin. All the resources will be ready to use when the status of the stack is CREATE_COMPLETE
.
You can check the CloudFormation stack by downloading the following file: CloudFormation stack
Note that the UserData
of the created Launch Template contains the following script:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="
--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
echo "ECS_CLUSTER=EcsSpotWorkshop" >> /etc/ecs/ecs.config
echo "ECS_ENABLE_SPOT_INSTANCE_DRAINING=true" >> /etc/ecs/ecs.config
echo "ECS_CONTAINER_STOP_TIMEOUT=90s" >> /etc/ecs/ecs.config
echo "ECS_ENABLE_CONTAINER_METADATA=true" >> /etc/ecs/ecs.config
--==MYBOUNDARY==--
What we are doing here is enabling Spot Instance Draining. When ECS Spot Instance draining is enabled on the instance, ECS receives the Spot Instance interruption notice and places the instance in DRAINING status. When a container instance is set to DRAINING, Amazon ECS prevents new tasks from being scheduled for placement on the container instance. To learn more about Spot instance interruption notices, visit Spot Instance interruption notices. For more information on how AWS Batch uses Amazon ECS, see the FAQs.
You will create other AWS resources using the AWS CLI in Cloud9, a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular programming languages, including JavaScript, Python, PHP, and more.
Navigate to the Cloud9 console and open the environment that was created for you. Execute the following commands to retrieve the outputs of the CloudFormation stack:
for output in $(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[].Outputs[].OutputKey' --output text)
do
export $output=$(aws cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[].Outputs[?OutputKey==`'$output'`].OutputValue' --output text)
eval "echo $output : \"\$$output\""
done
You can now start the workshop by heading to Risk pipeline.