Upgrade scale up/down lambdas to aws sdk v3 - #7061
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
dc1e2c9 to
4ac6cb3
Compare
| "@types/aws-lambda": "^8.10.72", | ||
| "@types/express": "^4.17.11", | ||
| "@types/jest": "^26.0.20", | ||
| "@types/jest": "29", |
There was a problem hiding this comment.
had to update jest because I kept getting some error with mocks, seems v3 isn't compatible with older jest?
There was a problem hiding this comment.
Shall we upgrade to 30 then, the latest version:
| /* istanbul ignore next */ | ||
| if (!kms) { | ||
| AWS.config.update({ | ||
| kms = new KMS({ |
There was a problem hiding this comment.
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}`; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
return value became something | undefined
There was a problem hiding this comment.
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-sdkv2 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'], |
There was a problem hiding this comment.
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.
| InstanceType: runnerParameters.runnerType.instance_type as RunInstancesCommandInput['InstanceType'], | |
| InstanceType: runnerParameters.runnerType.instance_type, |
| 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)!; |
There was a problem hiding this comment.
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.
| if (Metrics.baseMetricTypes.has(metric)) return Metrics.baseMetricTypes.get(metric)!; | |
| if (Metrics.baseMetricTypes.has(metric)) return Metrics.baseMetricTypes.get(metric) as StandardUnit; |
| nock.disableNetConnect(); | ||
|
|
||
| mocked(createClient).mockImplementation(produceMockedRedis); | ||
| (mocked(createClient) as any).mockImplementation(produceMockedRedis); |
There was a problem hiding this comment.
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.
| (mocked(createClient) as any).mockImplementation(produceMockedRedis); | |
| (mocked(createClient) as jest.MockedFunction<typeof createClient>).mockImplementation(produceMockedRedis); |
ZainRizvi
left a comment
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Shall we upgrade to 30 then, the latest version:
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?
Upgrade to aws sdk v3
Main change is getting rid of the
promisecalls since I think they just directly return promises instead of requestsThis changes a lot of mocks in the testing so I'm not sure how good running just
yarn testisTesting:
Mangled scaleDown to only run
listInstancesandlistSSMParametersIn
terraform-aws-github-runner/modules/runners/lambdas/runners:I also tried to terminate a runner and it worked
Deployed to pytorch-canary and ran some jobs, seems ok