Skip to content

Commit 0a4140e

Browse files
feat: update alpha modules to sdk v3 (#25895)
Updates alpha modules with custom resources to use NodeJS 18 and v3 of the AWS SDK. Since these CRs are pretty self-contained and safe to update, their handler code and runtime versions can be updated without any breakage for users. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent bd86993 commit 0a4140e

File tree

37 files changed

+31661
-1522
lines changed

37 files changed

+31661
-1522
lines changed

packages/@aws-cdk/aws-amplify-alpha/lib/asset-deployment-handler/handler.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// aws-sdk available at runtime for lambdas
2-
// eslint-disable-next-line import/no-extraneous-dependencies
3-
import { Amplify, S3 } from 'aws-sdk';
1+
import { Amplify } from '@aws-sdk/client-amplify';
2+
import { S3, GetObjectCommand } from '@aws-sdk/client-s3';
3+
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
44
import { AmplifyJobId, IsCompleteResponse, ResourceEvent, ResourceHandler } from './common';
55

66
export interface AmplifyAssetDeploymentProps {
@@ -38,8 +38,7 @@ export class AmplifyAssetDeploymentHandler extends ResourceHandler {
3838
appId: this.props.AppId,
3939
branchName: this.props.BranchName,
4040
maxResults: 1,
41-
})
42-
.promise();
41+
});
4342

4443
if (
4544
jobs.jobSummaries &&
@@ -49,22 +48,22 @@ export class AmplifyAssetDeploymentHandler extends ResourceHandler {
4948
}
5049

5150
// Create a pre-signed get URL of the asset so Amplify can retrieve it.
52-
const assetUrl = this.s3.getSignedUrl('getObject', {
51+
const command = new GetObjectCommand({
5352
Bucket: this.props.S3BucketName,
5453
Key: this.props.S3ObjectKey,
5554
});
55+
const assetUrl = await getSignedUrl(this.s3, command);
5656

5757
// Deploy the asset to Amplify.
5858
const deployment = await this.amplify
5959
.startDeployment({
6060
appId: this.props.AppId,
6161
branchName: this.props.BranchName,
6262
sourceUrl: assetUrl,
63-
})
64-
.promise();
63+
});
6564

6665
return {
67-
AmplifyJobId: deployment.jobSummary.jobId,
66+
AmplifyJobId: deployment.jobSummary?.jobId,
6867
};
6968
}
7069

@@ -110,19 +109,18 @@ export class AmplifyAssetDeploymentHandler extends ResourceHandler {
110109
appId: this.props.AppId,
111110
branchName: this.props.BranchName,
112111
jobId: jobId,
113-
})
114-
.promise();
112+
});
115113

116-
if (job.job.summary.status === 'SUCCEED') {
114+
if (job.job?.summary?.status === 'SUCCEED') {
117115
return {
118116
IsComplete: true,
119117
Data: {
120118
JobId: jobId,
121119
Status: job.job.summary.status,
122120
},
123121
};
124-
} if (job.job.summary.status === 'FAILED' || job.job.summary.status === 'CANCELLED') {
125-
throw new Error(`Amplify job failed with status: ${job.job.summary.status}`);
122+
} if (job.job?.summary?.status === 'FAILED' || job.job?.summary?.status === 'CANCELLED') {
123+
throw new Error(`Amplify job failed with status: ${job.job?.summary?.status}`);
126124
} else {
127125
return {
128126
IsComplete: false,

packages/@aws-cdk/aws-amplify-alpha/lib/asset-deployment-handler/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import { IsCompleteResponse } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';
3-
// aws-sdk available at runtime for lambdas
3+
// @aws-sdk/* modules available at runtime for lambdas >= Node18
44
// eslint-disable-next-line import/no-extraneous-dependencies
5-
import { Amplify, S3, config } from 'aws-sdk';
5+
import { Amplify } from '@aws-sdk/client-amplify';
6+
import { S3 } from '@aws-sdk/client-s3';
67
import { ResourceEvent } from './common';
78
import { AmplifyAssetDeploymentHandler } from './handler';
89

910
const AMPLIFY_ASSET_DEPLOYMENT_RESOURCE_TYPE = 'Custom::AmplifyAssetDeployment';
1011

11-
config.logger = console;
12-
13-
const amplify = new Amplify();
14-
const s3 = new S3({ signatureVersion: 'v4' });
12+
const sdkConfig = { logger: console };
13+
const amplify = new Amplify(sdkConfig);
14+
const s3 = new S3(sdkConfig);
1515

1616
export async function onEvent(event: ResourceEvent) {
1717
const provider = createResourceHandler(event);

packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CfnBranch } from 'aws-cdk-lib/aws-amplify';
1818
import { IApp } from './app';
1919
import { BasicAuth } from './basic-auth';
2020
import { renderEnvironmentVariables } from './utils';
21+
import { Runtime } from 'aws-cdk-lib/aws-lambda';
2122

2223
/**
2324
* A branch
@@ -248,6 +249,7 @@ class AmplifyAssetDeploymentProvider extends NestedStack {
248249
],
249250
}),
250251
],
252+
runtime: Runtime.NODEJS_18_X,
251253
},
252254
);
253255

@@ -266,6 +268,7 @@ class AmplifyAssetDeploymentProvider extends NestedStack {
266268
actions: ['amplify:GetJob*'],
267269
}),
268270
],
271+
runtime: Runtime.NODEJS_18_X,
269272
},
270273
);
271274

packages/@aws-cdk/aws-amplify-alpha/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@
8787
"@aws-cdk/integ-runner": "0.0.0",
8888
"@aws-cdk/cfn2ts": "0.0.0",
8989
"@aws-cdk/pkglint": "0.0.0",
90+
"@aws-sdk/client-amplify": "^3.347.0",
91+
"@aws-sdk/client-s3": "^3.347.0",
92+
"@aws-sdk/s3-request-presigner": "^3.347.0",
9093
"@types/jest": "^29.5.1",
91-
"aws-sdk": "^2.1379.0",
9294
"aws-cdk-lib": "0.0.0",
9395
"constructs": "^10.0.0"
9496
},

0 commit comments

Comments
 (0)