Skip to content

Commit

Permalink
Bump to Node20 (#72)
Browse files Browse the repository at this point in the history
* Bump to Node20
* Upgrade to aws-js-sdk-v3

---------

Co-authored-by: Connor Kirkpatrick <ckp@amazon.com>
  • Loading branch information
nicholasphair and ConnorKirk committed Apr 10, 2024
1 parent 0982d8f commit bd2d4b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
37 changes: 18 additions & 19 deletions source/witch/witch.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const aws = require('aws-sdk');
const fs = require('fs');
const path = require('path');
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
const fs = require('node:fs');
const path = require('node:path');
const mime = require('mime-types');
const https = require('https');
const url = require('url');
const https = require('node:https');
const url = require('node:url');

const s3 = new aws.S3();
const s3Client = new S3Client();

const SUCCESS = 'SUCCESS';
const FAILED = 'FAILED';

const { BUCKET } = process.env;

exports.staticHandler = function (event, context) {
exports.staticHandler = (event, context) => {
if (event.RequestType !== 'Create' && event.RequestType !== 'Update') {
return respond(event, context, SUCCESS, {});
}
Expand All @@ -23,16 +23,16 @@ exports.staticHandler = function (event, context) {

console.log(`${file} -> ${fileType}`);

return s3
.upload({
return s3Client.send(
new PutObjectCommand({
Body: fs.createReadStream(file),
Bucket: BUCKET,
ContentType: fileType,
Key: file,
ACL: 'private',
})
.promise();
}),
);
})
)
.then((msg) => {
respond(event, context, SUCCESS, {});
Expand Down Expand Up @@ -63,12 +63,11 @@ function respond(
responseStatus,
responseData,
physicalResourceId,
noEcho,
noEcho
) {
const responseBody = JSON.stringify({
Status: responseStatus,
Reason:
'See the details in CloudWatch Log Stream: ' + context.logStreamName,
Reason: `See the details in CloudWatch Log Stream: ${context.logStreamName}`,
PhysicalResourceId: physicalResourceId || context.logStreamName,
StackId: event.StackId,
RequestId: event.RequestId,
Expand All @@ -91,14 +90,14 @@ function respond(
},
};

const request = https.request(options, function (response) {
console.log('Status code: ' + response.statusCode);
console.log('Status message: ' + response.statusMessage);
const request = https.request(options, (response) => {
console.log(`Status code: ${response.statusCode}`);
console.log(`Status message: ${response.statusMessage}`);
context.done();
});

request.on('error', function (error) {
console.log('send(..) failed executing https.request(..): ' + error);
request.on('error', (error) => {
console.log(`send(..) failed executing https.request(..): ${error}`);
context.done();
});

Expand Down
4 changes: 2 additions & 2 deletions templates/custom-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Resources:
Properties:
ContentUri: ../witch.zip
CompatibleRuntimes:
- nodejs16.x
- nodejs20.x

CopyRole:
Type: 'AWS::IAM::Role'
Expand Down Expand Up @@ -87,7 +87,7 @@ Resources:
Layers:
- !Ref CopyLayerVersion
Role: !GetAtt CopyRole.Arn
Runtime: nodejs16.x
Runtime: nodejs20.x
Timeout: 300

Outputs:
Expand Down
4 changes: 2 additions & 2 deletions templates/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AWSTemplateFormatVersion: 2010-09-09
Description: |
ACFS3 - S3 Static site with CF and ACM
https://github.com/aws-samples/amazon-cloudfront-secure-static-site
(uksb-1qnk6ni7b) (version:v0.5)
(uksb-1qnk6ni7b) (version:v0.12)
Metadata:
AWS::CloudFormation::Interface:
Expand All @@ -16,7 +16,7 @@ Metadata:
Mappings:
Solution:
Constants:
Version: 'v0.11'
Version: 'v0.12'

Rules:
OnlyUsEast1:
Expand Down

0 comments on commit bd2d4b3

Please sign in to comment.