Skip to content

Upgrade scale up/down lambdas to aws sdk v3 - #7061

Merged
clee2000 merged 33 commits into
mainfrom
csl/aws_sdk
Sep 5, 2025
Merged

Upgrade scale up/down lambdas to aws sdk v3#7061
clee2000 merged 33 commits into
mainfrom
csl/aws_sdk

Conversation

@clee2000

@clee2000 clee2000 commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

Upgrade to aws sdk v3

Main change is getting rid of the promise calls since I think they just directly return promises instead of requests

This changes a lot of mocks in the testing so I'm not sure how good running just yarn test is

Testing:
Mangled scaleDown to only run listInstances and listSSMParameters
In terraform-aws-github-runner/modules/runners/lambdas/runners:

yarn build; cd dist;node -e 'require("./index").scaleDown({}, {}, {});' > t.log    

I also tried to terminate a runner and it worked

Deployed to pytorch-canary and ran some jobs, seems ok

@vercel

vercel Bot commented Aug 28, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Updated (UTC)
torchci Ignored Ignored Preview Sep 2, 2025 9:06pm

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 28, 2025
"@types/aws-lambda": "^8.10.72",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/jest": "29",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to update jest because I kept getting some error with mocks, seems v3 isn't compatible with older jest?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we upgrade to 30 then, the latest version:

/* istanbul ignore next */
if (!kms) {
AWS.config.update({
kms = new KMS({

@clee2000 clee2000 Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something about global configs not being supported anymore and to just do it in the initialization of the client?

const accountId = splitARN[4];
const queueName = splitARN[5];
return sqs.endpoint.href + accountId + '/' + queueName;
return `https://sqs.${region}.amazonaws.com/${accountId}/${queueName}`;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endpoint.href no longer seems to be a thing, so I construct it manually, hopefully it's correct. There's also a getQueueUrl function but it returns string | undefined

});
});
if (response.Failed.length || response.Successful.length < events.length) {
const failedCount = response.Failed?.length ?? 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return value became something | undefined

@clee2000 clee2000 changed the title [WIP] Upgrade scale up/down lambdas to aws sdk v3 Upgrade scale up/down lambdas to aws sdk v3 Sep 2, 2025
@clee2000
clee2000 marked this pull request as ready for review September 2, 2025 16:17
@ZainRizvi
ZainRizvi requested a review from Copilot September 3, 2025 19:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR upgrades the Lambda functions from AWS SDK v2 to v3, removing the .promise() calls since v3 directly returns promises. The upgrade includes updating dependencies, imports, type definitions, and comprehensive test mock updates.

  • Migrates from aws-sdk v2 to individual AWS SDK v3 client packages
  • Updates all service instantiations and removes .promise() calls
  • Refactors test mocks to align with v3's direct promise returns

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/sqs.ts Updates SQS service calls and queue URL construction for v3
terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/runners.ts Migrates EC2 and SSM service calls to v3 with updated type imports
terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/metrics.ts Updates CloudWatch client and metric type definitions
terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/kms/index.ts Migrates KMS client initialization and decrypt calls
terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts Updates Secrets Manager client import and service calls
terraform-aws-github-runner/modules/runners/lambdas/runners/package.json Replaces aws-sdk v2 with individual v3 client packages and updates Jest
Multiple test files Updates all mocks to remove .promise() returns and use direct promise resolution

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Version: launchTemplateVersion,
},
InstanceType: runnerParameters.runnerType.instance_type,
InstanceType: runnerParameters.runnerType.instance_type as RunInstancesCommandInput['InstanceType'],

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type assertion here suggests a potential mismatch between the defined instance_type and what AWS SDK v3 expects. Consider updating the RunnerType interface's instance_type field to use the proper SDK v3 type instead of relying on type assertions.

Suggested change
InstanceType: runnerParameters.runnerType.instance_type as RunInstancesCommandInput['InstanceType'],
InstanceType: runnerParameters.runnerType.instance_type,

Copilot uses AI. Check for mistakes.
protected getMetricType(metric: string): string {
if (Metrics.baseMetricTypes.has(metric)) return Metrics.baseMetricTypes.get(metric) as string;
protected getMetricType(metric: string): StandardUnit {
if (Metrics.baseMetricTypes.has(metric)) return Metrics.baseMetricTypes.get(metric)!;

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the non-null assertion operator (!) after a .has() check is redundant. The has() check already guarantees the value exists, so you can safely cast or use as-assertion if needed for typing.

Suggested change
if (Metrics.baseMetricTypes.has(metric)) return Metrics.baseMetricTypes.get(metric)!;
if (Metrics.baseMetricTypes.has(metric)) return Metrics.baseMetricTypes.get(metric) as StandardUnit;

Copilot uses AI. Check for mistakes.
nock.disableNetConnect();

mocked(createClient).mockImplementation(produceMockedRedis);
(mocked(createClient) as any).mockImplementation(produceMockedRedis);

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'as any' defeats the purpose of TypeScript's type safety. Consider properly typing the mocked function or using a more specific type assertion that maintains type safety.

Suggested change
(mocked(createClient) as any).mockImplementation(produceMockedRedis);
(mocked(createClient) as jest.MockedFunction<typeof createClient>).mockImplementation(produceMockedRedis);

Copilot uses AI. Check for mistakes.

@ZainRizvi ZainRizvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, but please deploy these changes to canary and verify scale up/down works over there before merging

"@types/aws-lambda": "^8.10.72",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/jest": "29",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we upgrade to 30 then, the latest version:

clee2000 added a commit that referenced this pull request Sep 5, 2025
Similar to #7061 

Mostly just getting rid of `promise()`

Testing:
just `yarn test` but idk how helpful that is since it mocks everything
Deployed to pytorch-canary and it seems ok?
@clee2000
clee2000 merged commit 12626a2 into main Sep 5, 2025
5 checks passed
@clee2000
clee2000 deleted the csl/aws_sdk branch September 5, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants