1- const aws = require ( 'aws-sdk' ) ;
2- const fs = require ( 'fs' ) ;
3- const path = require ( 'path' ) ;
1+ const { S3Client , PutObjectCommand } = require ( '@ aws-sdk/client-s3 ' ) ;
2+ const fs = require ( 'node: fs' ) ;
3+ const path = require ( 'node: path' ) ;
44const mime = require ( 'mime-types' ) ;
5- const https = require ( 'https' ) ;
6- const url = require ( 'url' ) ;
5+ const https = require ( 'node: https' ) ;
6+ const url = require ( 'node: url' ) ;
77
8- const s3 = new aws . S3 ( ) ;
8+ const s3Client = new S3Client ( ) ;
99
1010const SUCCESS = 'SUCCESS' ;
1111const FAILED = 'FAILED' ;
1212
1313const { BUCKET } = process . env ;
1414
15- exports . staticHandler = function ( event , context ) {
15+ exports . staticHandler = ( event , context ) => {
1616 if ( event . RequestType !== 'Create' && event . RequestType !== 'Update' ) {
1717 return respond ( event , context , SUCCESS , { } ) ;
1818 }
@@ -23,16 +23,16 @@ exports.staticHandler = function (event, context) {
2323
2424 console . log ( `${ file } -> ${ fileType } ` ) ;
2525
26- return s3
27- . upload ( {
26+ return s3Client . send (
27+ new PutObjectCommand ( {
2828 Body : fs . createReadStream ( file ) ,
2929 Bucket : BUCKET ,
3030 ContentType : fileType ,
3131 Key : file ,
3232 ACL : 'private' ,
3333 } )
34- . promise ( ) ;
35- } ) ,
34+ ) ;
35+ } )
3636 )
3737 . then ( ( msg ) => {
3838 respond ( event , context , SUCCESS , { } ) ;
@@ -63,12 +63,11 @@ function respond(
6363 responseStatus ,
6464 responseData ,
6565 physicalResourceId ,
66- noEcho ,
66+ noEcho
6767) {
6868 const responseBody = JSON . stringify ( {
6969 Status : responseStatus ,
70- Reason :
71- 'See the details in CloudWatch Log Stream: ' + context . logStreamName ,
70+ Reason : `See the details in CloudWatch Log Stream: ${ context . logStreamName } ` ,
7271 PhysicalResourceId : physicalResourceId || context . logStreamName ,
7372 StackId : event . StackId ,
7473 RequestId : event . RequestId ,
@@ -91,14 +90,14 @@ function respond(
9190 } ,
9291 } ;
9392
94- const request = https . request ( options , function ( response ) {
95- console . log ( ' Status code: ' + response . statusCode ) ;
96- console . log ( ' Status message: ' + response . statusMessage ) ;
93+ const request = https . request ( options , ( response ) => {
94+ console . log ( ` Status code: ${ response . statusCode } ` ) ;
95+ console . log ( ` Status message: ${ response . statusMessage } ` ) ;
9796 context . done ( ) ;
9897 } ) ;
9998
100- request . on ( 'error' , function ( error ) {
101- console . log ( ' send(..) failed executing https.request(..): ' + error ) ;
99+ request . on ( 'error' , ( error ) => {
100+ console . log ( ` send(..) failed executing https.request(..): ${ error } ` ) ;
102101 context . done ( ) ;
103102 } ) ;
104103
0 commit comments