Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update alpha modules to sdk v3 #25895

Merged
merged 18 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// aws-sdk available at runtime for lambdas
// eslint-disable-next-line import/no-extraneous-dependencies
import { Amplify, S3 } from 'aws-sdk';
import { Amplify } from '@aws-sdk/client-amplify';
import { S3, GetObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { AmplifyJobId, IsCompleteResponse, ResourceEvent, ResourceHandler } from './common';

export interface AmplifyAssetDeploymentProps {
Expand Down Expand Up @@ -38,8 +38,7 @@ export class AmplifyAssetDeploymentHandler extends ResourceHandler {
appId: this.props.AppId,
branchName: this.props.BranchName,
maxResults: 1,
})
.promise();
});

if (
jobs.jobSummaries &&
Expand All @@ -49,22 +48,22 @@ export class AmplifyAssetDeploymentHandler extends ResourceHandler {
}

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

// Deploy the asset to Amplify.
const deployment = await this.amplify
.startDeployment({
appId: this.props.AppId,
branchName: this.props.BranchName,
sourceUrl: assetUrl,
})
.promise();
});

return {
AmplifyJobId: deployment.jobSummary.jobId,
AmplifyJobId: deployment.jobSummary?.jobId,
MrArnoldPalmer marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down Expand Up @@ -110,19 +109,18 @@ export class AmplifyAssetDeploymentHandler extends ResourceHandler {
appId: this.props.AppId,
branchName: this.props.BranchName,
jobId: jobId,
})
.promise();
});

if (job.job.summary.status === 'SUCCEED') {
if (job.job?.summary?.status === 'SUCCEED') {
return {
IsComplete: true,
Data: {
JobId: jobId,
Status: job.job.summary.status,
},
};
} if (job.job.summary.status === 'FAILED' || job.job.summary.status === 'CANCELLED') {
throw new Error(`Amplify job failed with status: ${job.job.summary.status}`);
} if (job.job?.summary?.status === 'FAILED' || job.job?.summary?.status === 'CANCELLED') {
throw new Error(`Amplify job failed with status: ${job.job?.summary?.status}`);
} else {
return {
IsComplete: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { IsCompleteResponse } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';
// aws-sdk available at runtime for lambdas
// @aws-sdk/* modules available at runtime for lambdas >= Node18
// eslint-disable-next-line import/no-extraneous-dependencies
import { Amplify, S3, config } from 'aws-sdk';
import { Amplify } from '@aws-sdk/client-amplify';
import { S3 } from '@aws-sdk/client-s3';
import { ResourceEvent } from './common';
import { AmplifyAssetDeploymentHandler } from './handler';

const AMPLIFY_ASSET_DEPLOYMENT_RESOURCE_TYPE = 'Custom::AmplifyAssetDeployment';

config.logger = console;

const amplify = new Amplify();
const s3 = new S3({ signatureVersion: 'v4' });
const sdkConfig = { logger: console };
const amplify = new Amplify(sdkConfig);
const s3 = new S3(sdkConfig);

export async function onEvent(event: ResourceEvent) {
const provider = createResourceHandler(event);
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CfnBranch } from 'aws-cdk-lib/aws-amplify';
import { IApp } from './app';
import { BasicAuth } from './basic-auth';
import { renderEnvironmentVariables } from './utils';
import { Runtime } from 'aws-cdk-lib/aws-lambda';

/**
* A branch
Expand Down Expand Up @@ -248,6 +249,7 @@ class AmplifyAssetDeploymentProvider extends NestedStack {
],
}),
],
runtime: Runtime.NODEJS_18_X,
},
);

Expand All @@ -266,6 +268,7 @@ class AmplifyAssetDeploymentProvider extends NestedStack {
actions: ['amplify:GetJob*'],
}),
],
runtime: Runtime.NODEJS_18_X,
},
);

Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-amplify-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@
"@aws-cdk/integ-runner": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@aws-sdk/client-amplify": "^3.347.0",
"@aws-sdk/client-s3": "^3.347.0",
"@aws-sdk/s3-request-presigner": "^3.347.0",
"@types/jest": "^29.5.1",
"aws-sdk": "^2.1379.0",
"aws-cdk-lib": "0.0.0",
"constructs": "^10.0.0"
},
Expand Down
Loading