|
3 | 3 |
|
4 | 4 | const core = require("@actions/core"); |
5 | 5 | 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 | + |
7 | 17 | const assert = require("assert"); |
8 | 18 |
|
9 | 19 | module.exports = { |
@@ -38,19 +48,22 @@ async function build(sdk, params, config) { |
38 | 48 | // Invoke the lambda to start the build |
39 | 49 | const buildTime = (Date.now() / 1000).toString(); |
40 | 50 | 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 | + ); |
54 | 67 |
|
55 | 68 | await core.notice(`Built image tag: ${imageTag}`); |
56 | 69 |
|
@@ -81,17 +94,21 @@ async function waitForBuildEndTime( |
81 | 94 | let errObject = false; |
82 | 95 | // Check the state |
83 | 96 | const [batch, cloudWatch = {}] = await Promise.all([ |
84 | | - codeBuild.batchGetBuilds({ ids: [id] }).promise(), |
| 97 | + codeBuild.send( |
| 98 | + new BatchGetBuildsCommand({ |
| 99 | + ids: [id], |
| 100 | + }) |
| 101 | + ), |
85 | 102 | !hideCloudWatchLogs && |
86 | 103 | logGroupName && |
87 | | - cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists |
88 | | - .getLogEvents({ |
| 104 | + cloudWatchLogs.send( |
| 105 | + new GetLogEventsCommand({ |
89 | 106 | logGroupName, |
90 | 107 | logStreamName, |
91 | 108 | startFromHead, |
92 | 109 | nextToken, |
93 | 110 | }) |
94 | | - .promise(), |
| 111 | + ), |
95 | 112 | ]).catch((err) => { |
96 | 113 | errObject = err; |
97 | 114 | /* Returning [] here so that the assignment above |
@@ -252,15 +269,15 @@ function inputs2Parameters(inputs) { |
252 | 269 | } |
253 | 270 |
|
254 | 271 | function buildSdk() { |
255 | | - const codeBuild = new aws.CodeBuild({ |
| 272 | + const codeBuild = new CodeBuildClient({ |
256 | 273 | customUserAgent: "brave-intl/aws-codebuild-run-build", |
257 | 274 | }); |
258 | 275 |
|
259 | | - const cloudWatchLogs = new aws.CloudWatchLogs({ |
| 276 | + const cloudWatchLogs = new CloudWatchLogsClient({ |
260 | 277 | customUserAgent: "brave-intl/aws-codebuild-run-build", |
261 | 278 | }); |
262 | 279 |
|
263 | | - const lambda = new aws.Lambda({ |
| 280 | + const lambda = new LambdaClient({ |
264 | 281 | customUserAgent: "brave-intl/aws-codebuild-run-build", |
265 | 282 | }); |
266 | 283 |
|
|
0 commit comments