Skip to content

Commit 99c977d

Browse files
authored
runners: Add expiration policy to SSM parameters (#6855)
Instead of doing expensive cleanups we can rely on SSM parameter policies to do the cleanup for us! This is a workaround to avoid the need to do expensive cleanup of SSM parameters. Signed-off-by: Eli Uriegas <[email protected]>
1 parent 4556a13 commit 99c977d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,26 @@ describe('createRunner', () => {
13401340
Name: 'wg113-i-1234',
13411341
Value: 'us-east-1-BLAH',
13421342
Type: 'SecureString',
1343+
Policies: expect.any(String),
13431344
});
1345+
1346+
// Verify the Policies parameter contains the correct expiration policy structure
1347+
const putParameterCall = mockSSM.putParameter.mock.calls[0][0];
1348+
const policies = JSON.parse(putParameterCall.Policies);
1349+
expect(policies).toEqual({
1350+
Type: 'Expiration',
1351+
Version: '1.0',
1352+
Attributes: {
1353+
Timestamp: expect.any(String),
1354+
},
1355+
});
1356+
1357+
// Verify the timestamp is approximately 30 minutes in the future
1358+
const expirationTime = new Date(policies.Attributes.Timestamp);
1359+
const now = Date.now();
1360+
const timeDiff = expirationTime.getTime() - now;
1361+
expect(timeDiff).toBeGreaterThan(25 * 60 * 1000); // at least 25 minutes (allowing for test execution time)
1362+
expect(timeDiff).toBeLessThan(35 * 60 * 1000); // at most 35 minutes (allowing for clock differences)
13441363
});
13451364

13461365
it('creates ssm experiment parameters when joining experiment', async () => {
@@ -1384,6 +1403,7 @@ describe('createRunner', () => {
13841403
Name: 'wg113-i-1234',
13851404
Value: 'us-east-1-BLAH #ON_AMI_EXPERIMENT',
13861405
Type: 'SecureString',
1406+
Policies: expect.any(String),
13871407
});
13881408
expect(mockEC2.runInstances).toBeCalledTimes(1);
13891409
expect(mockEC2.runInstances).toBeCalledWith(

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ async function addSSMParameterRunnerConfig(
534534
Name: parameterName,
535535
Value: runnerConfig,
536536
Type: 'SecureString',
537+
// NOTE: This does need to be a string, check docs at:
538+
// https://docs.aws.amazon.com/systems-manager/latest/userguide/example_ssm_PutParameter_section.html
539+
Policies: JSON.stringify({
540+
Type: 'Expiration',
541+
Version: '1.0',
542+
Attributes: {
543+
Timestamp: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
544+
},
545+
}),
537546
})
538547
.promise();
539548
return parameterName;

0 commit comments

Comments
 (0)