From ff693cfe1d6b1d9a8fe6950fb82b61e59571b1f1 Mon Sep 17 00:00:00 2001 From: Samuel Chiang Date: Wed, 11 Oct 2023 09:29:25 -0700 Subject: [PATCH] Self Terminate ec2 tests instances after 1 hour (#1233) The new ec2 test framework doesn't mesh well with our job pruner. Codebuild just "stops" the instance without giving a signal to the executing script, so trap cleanup is not executed. This lets the ec2 self-terminate once a certain amount of time has passed. --- tests/ci/cdk/cdk/ssm/general_test_run_ssm_document.yaml | 3 +++ tests/ci/run_ec2_test_framework.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/tests/ci/cdk/cdk/ssm/general_test_run_ssm_document.yaml b/tests/ci/cdk/cdk/ssm/general_test_run_ssm_document.yaml index 28b90d14f1..7bede07f2a 100644 --- a/tests/ci/cdk/cdk/ssm/general_test_run_ssm_document.yaml +++ b/tests/ci/cdk/cdk/ssm/general_test_run_ssm_document.yaml @@ -10,6 +10,9 @@ mainSteps: inputs: timeoutSeconds: '7200' runCommand: + # Fallback plan to shut down the ec2 instance in 60 minutes in case it's not terminated. + # Codebuild just "stops" the instance calling the script, so "trap cleanup" is not executed. + - shutdown -P +60 - sudo -i - export DEBIAN_FRONTEND=noninteractive - export CPU_TYPE=$(dpkg --print-architecture) diff --git a/tests/ci/run_ec2_test_framework.sh b/tests/ci/run_ec2_test_framework.sh index 9c121e1df3..b2cfcfce25 100755 --- a/tests/ci/run_ec2_test_framework.sh +++ b/tests/ci/run_ec2_test_framework.sh @@ -36,6 +36,7 @@ create_ec2_instances() { --tag-specifications 'ResourceType="instance",Tags=[{Key="aws-lc",Value="aws-lc-ci-ec2-test-framework-ec2-x86-instance"}]' \ --iam-instance-profile Name=aws-lc-ci-ec2-test-framework-ec2-profile \ --placement 'AvailabilityZone=us-west-2a' \ + --instance-initiated-shutdown-behavior terminate \ --query Instances[*].InstanceId --output text)" echo "${instance_id}" }