Skip to content

Commit 99fa268

Browse files
committed
Upgrade to aws-js-sdk-v3
1 parent 2c07ba9 commit 99fa268

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

source/witch/witch.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
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');
44
const 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

1010
const SUCCESS = 'SUCCESS';
1111
const FAILED = 'FAILED';
1212

1313
const { 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

templates/main.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ AWSTemplateFormatVersion: 2010-09-09
22
Description: |
33
ACFS3 - S3 Static site with CF and ACM
44
https://github.com/aws-samples/amazon-cloudfront-secure-static-site
5-
(uksb-1qnk6ni7b) (version:v0.5)
5+
(uksb-1qnk6ni7b) (version:v0.12)
66
77
Metadata:
88
AWS::CloudFormation::Interface:
@@ -16,7 +16,7 @@ Metadata:
1616
Mappings:
1717
Solution:
1818
Constants:
19-
Version: 'v0.11'
19+
Version: 'v0.12'
2020

2121
Rules:
2222
OnlyUsEast1:

0 commit comments

Comments
 (0)