Skip to content
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
18 changes: 9 additions & 9 deletions java/my-widget-service/resources/widgets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const AWS = require('aws-sdk');
const S3 = new AWS.S3();
const { S3 } = require("@aws-sdk/client-s3");
const s3 = new S3();

const bucketName = process.env.BUCKET;

Expand All @@ -12,7 +12,7 @@ exports.main = async function(event, context) {
if (method === "GET") {
// GET / to get the names of all widgets
if (event.path === "/") {
const data = await S3.listObjectsV2({ Bucket: bucketName }).promise();
const data = await s3.listObjectsV2({ Bucket: bucketName });
var body = {
widgets: data.Contents.map(function(e) { return e.Key })
};
Expand All @@ -25,8 +25,8 @@ exports.main = async function(event, context) {

if (widgetName) {
// GET /name to get info on widget name
const data = await S3.getObject({ Bucket: bucketName, Key: widgetName}).promise();
var body = data.Body.toString('utf-8');
const data = await s3.getObject({ Bucket: bucketName, Key: widgetName});
var body = await data.Body.transformToString();

return {
statusCode: 200,
Expand All @@ -53,12 +53,12 @@ exports.main = async function(event, context) {

var base64data = new Buffer(data, 'binary');

await S3.putObject({
await s3.putObject({
Bucket: bucketName,
Key: widgetName,
Body: base64data,
ContentType: 'application/json'
}).promise();
});

return {
statusCode: 200,
Expand All @@ -78,9 +78,9 @@ exports.main = async function(event, context) {
};
}

await S3.deleteObject({
await s3.deleteObject({
Bucket: bucketName, Key: widgetName
}).promise();
});

return {
statusCode: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MyWidgetServiceStack(final Construct scope, final String id) {
.code(Code.fromAsset("resources"))
.handler("widgets.main")
.timeout(Duration.seconds(300))
.runtime(Runtime.NODEJS_16_X)
.runtime(Runtime.NODEJS_20_X)
.environment(environmentVariables)
.build();

Expand Down