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

Bump to Node20 #72

Merged
merged 2 commits into from
Apr 10, 2024
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
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
Loading