Skip to content

Commit 7f7b8ab

Browse files
committed
Migrate AWS SDK to V3
1 parent 8477565 commit 7f7b8ab

File tree

5 files changed

+77009
-78621
lines changed

5 files changed

+77009
-78621
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ outputs:
2323
aws-build-id:
2424
description: 'The AWS CodeBuild Build ID for this build.'
2525
runs:
26-
using: 'node16'
26+
using: 'node20'
2727
main: 'dist/index.js'

code-build.js

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
const core = require("@actions/core");
55
const github = require("@actions/github");
6-
const aws = require("aws-sdk");
6+
7+
const {
8+
CloudWatchLogsClient,
9+
GetLogEventsCommand,
10+
} = require("@aws-sdk/client-cloudwatch-logs");
11+
const {
12+
CodeBuildClient,
13+
BatchGetBuildsCommand,
14+
} = require("@aws-sdk/client-codebuild");
15+
const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda");
16+
717
const assert = require("assert");
818

919
module.exports = {
@@ -38,19 +48,22 @@ async function build(sdk, params, config) {
3848
// Invoke the lambda to start the build
3949
const buildTime = (Date.now() / 1000).toString();
4050
const imageTag = `${params.sourceVersion}-${Math.floor(buildTime)}`;
41-
const lambdaParams = {
42-
FunctionName: "GeneralDockerBuildPipelineLambdaFunction",
43-
Payload: JSON.stringify({
44-
owner: params.owner,
45-
repo: params.repo,
46-
branch: params.branch,
47-
sourceVersion: params.sourceVersion,
48-
reproducible: params.reproducible,
49-
imageTag,
50-
}),
51-
};
52-
const response = await sdk.lambda.invoke(lambdaParams).promise();
53-
const start = JSON.parse(JSON.parse(response.Payload));
51+
const response = await sdk.lambda.send(
52+
new InvokeCommand({
53+
FunctionName: "GeneralDockerBuildPipelineLambdaFunction",
54+
Payload: JSON.stringify({
55+
owner: params.owner,
56+
repo: params.repo,
57+
branch: params.branch,
58+
sourceVersion: params.sourceVersion,
59+
reproducible: params.reproducible,
60+
imageTag,
61+
}),
62+
})
63+
);
64+
const start = JSON.parse(
65+
JSON.parse(Buffer.from(response.Payload).toString())
66+
);
5467

5568
await core.notice(`Built image tag: ${imageTag}`);
5669

@@ -81,17 +94,21 @@ async function waitForBuildEndTime(
8194
let errObject = false;
8295
// Check the state
8396
const [batch, cloudWatch = {}] = await Promise.all([
84-
codeBuild.batchGetBuilds({ ids: [id] }).promise(),
97+
codeBuild.send(
98+
new BatchGetBuildsCommand({
99+
ids: [id],
100+
})
101+
),
85102
!hideCloudWatchLogs &&
86103
logGroupName &&
87-
cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists
88-
.getLogEvents({
104+
cloudWatchLogs.send(
105+
new GetLogEventsCommand({
89106
logGroupName,
90107
logStreamName,
91108
startFromHead,
92109
nextToken,
93110
})
94-
.promise(),
111+
),
95112
]).catch((err) => {
96113
errObject = err;
97114
/* Returning [] here so that the assignment above
@@ -252,15 +269,15 @@ function inputs2Parameters(inputs) {
252269
}
253270

254271
function buildSdk() {
255-
const codeBuild = new aws.CodeBuild({
272+
const codeBuild = new CodeBuildClient({
256273
customUserAgent: "brave-intl/aws-codebuild-run-build",
257274
});
258275

259-
const cloudWatchLogs = new aws.CloudWatchLogs({
276+
const cloudWatchLogs = new CloudWatchLogsClient({
260277
customUserAgent: "brave-intl/aws-codebuild-run-build",
261278
});
262279

263-
const lambda = new aws.Lambda({
280+
const lambda = new LambdaClient({
264281
customUserAgent: "brave-intl/aws-codebuild-run-build",
265282
});
266283

0 commit comments

Comments
 (0)