Skip to content

Commit a98113d

Browse files
authored
Upgrade webhook lambda for scale up/down to aws sdk v3 (#7077)
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?
1 parent 200cb0c commit a98113d

File tree

4 files changed

+936
-211
lines changed

4 files changed

+936
-211
lines changed

terraform-aws-github-runner/modules/webhook/lambdas/webhook/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@typescript-eslint/eslint-plugin": "^7.10.0",
2323
"@typescript-eslint/parser": "^7.10.0",
2424
"@vercel/ncc": "^0.38.1",
25-
"aws-sdk": "^2.1627.0",
2625
"body-parser": "^1.20.3",
2726
"eslint": "8.56.0",
2827
"express": "^4.17.1",
@@ -31,13 +30,15 @@
3130
"prettier": "^3.2.5",
3231
"ts-jest": "^28.0.8",
3332
"ts-node-dev": "^2.0.0",
34-
"typescript-eslint": "^7.10.0",
35-
"typescript": "^4.3.0"
33+
"typescript": "^4.3.0",
34+
"typescript-eslint": "^7.10.0"
3635
},
3736
"dependencies": {
37+
"@aws-sdk/client-kms": "^3.879.0",
38+
"@aws-sdk/client-sqs": "^3.879.0",
3839
"@octokit/rest": "^20.1.1",
40+
"@octokit/webhooks": "^12.2.0",
3941
"@octokit/webhooks-methods": "^5.1.0",
40-
"@octokit/webhooks-types": "^7.5.1",
41-
"@octokit/webhooks": "^12.2.0"
42+
"@octokit/webhooks-types": "^7.5.1"
4243
}
4344
}

terraform-aws-github-runner/modules/webhook/lambdas/webhook/src/kms/index.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
import { KMS } from 'aws-sdk';
2-
import AWS from 'aws-sdk';
1+
import { KMS } from '@aws-sdk/client-kms';
32

4-
AWS.config.update({
5-
region: process.env.AWS_REGION,
6-
});
7-
8-
const kms = new KMS();
3+
const kms = new KMS({ region: process.env.AWS_REGION });
94

105
export async function decrypt(encrypted: string, key: string, environmentName: string): Promise<string | undefined> {
116
let result: string | undefined = encrypted;
127
if (key != undefined) {
13-
const decrypted = await kms
14-
.decrypt({
15-
CiphertextBlob: Buffer.from(encrypted, 'base64'),
16-
KeyId: key,
17-
EncryptionContext: {
18-
['Environment']: environmentName,
19-
},
20-
})
21-
.promise();
8+
const decrypted = await kms.decrypt({
9+
CiphertextBlob: Buffer.from(encrypted, 'base64') as Uint8Array,
10+
KeyId: key,
11+
EncryptionContext: {
12+
['Environment']: environmentName,
13+
},
14+
});
2215
result = decrypted.Plaintext?.toString();
2316
}
2417
return result;
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import { SQS } from 'aws-sdk';
2-
import AWS from 'aws-sdk';
1+
import { SQS } from '@aws-sdk/client-sqs';
32

4-
AWS.config.update({
5-
region: process.env.AWS_REGION,
6-
});
7-
8-
const sqs = new SQS();
3+
const sqs = new SQS({ region: process.env.AWS_REGION });
94

105
export interface ActionRequestMessage {
116
id: number;
@@ -22,10 +17,8 @@ const NUM_MESSAGE_GROUPS = process.env.NUM_MESSAGE_GROUPS !== undefined ? parseI
2217

2318
export const sendActionRequest = async (message: ActionRequestMessage) => {
2419
console.info(`Sending message: ${JSON.stringify(message)}`);
25-
await sqs
26-
.sendMessage({
27-
QueueUrl: String(process.env.SQS_URL_WEBHOOK),
28-
MessageBody: JSON.stringify(message),
29-
})
30-
.promise();
20+
await sqs.sendMessage({
21+
QueueUrl: String(process.env.SQS_URL_WEBHOOK),
22+
MessageBody: JSON.stringify(message),
23+
});
3124
};

0 commit comments

Comments
 (0)