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 ' ;
44import { AmplifyJobId , IsCompleteResponse , ResourceEvent , ResourceHandler } from './common' ;
55
66export 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 ,
0 commit comments