Skip to content

Instantly share code, notes, and snippets.

@igoralves1
Created August 26, 2024 18:53
Show Gist options
  • Save igoralves1/d97e2bbdd2abbd970b4aa6a61cc62ea9 to your computer and use it in GitHub Desktop.
Save igoralves1/d97e2bbdd2abbd970b4aa6a61cc62ea9 to your computer and use it in GitHub Desktop.
local s3
exports.hello = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v4.0! Your function executed successfully!'
})
};
};
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
module.exports.webhook = (event, context, callback) => {
const client = new S3Client({
forcePathStyle: true,
credentials: {
accessKeyId: "S3RVER", // This specific key is required when working offline
secretAccessKey: "S3RVER",
},
endpoint: "http://localhost:4569",
});
client
.send(
new PutObjectCommand({
Bucket: "052a36f5fb9elocalbucketz",
Key: "1234",
Body: Buffer.from("abcd"),
})
)
.then(() => callback(null, "ok"));
};
module.exports.s3hook = (event, context) => {
console.log(JSON.stringify(event));
console.log(JSON.stringify(context));
console.log(JSON.stringify(process.env));
};
# "org" ensures this Service is used with the correct Serverless Framework Access Key.
org: igoralves1
# "app" enables Serverless Framework Dashboard features and sharing them with other Services.
app: ftest
# "service" is the name of this project. This will also be added to your AWS resource names.
service: ft
plugins:
- serverless-offline
provider:
name: aws
runtime: nodejs20.x
custom:
s3:
host: localhost
port: 8000
directory: /tmp
resources:
Resources:
NewResource:
Type: AWS::S3::Bucket
Properties:
BucketName: 052a36f5fb9elocalbucketz
functions:
hello:
handler: handler.hello
testapi:
handler: testapi.testapi
events:
- httpApi:
method: POST
path: /testapi
webhook:
handler: handler.webhook
events:
- http:
method: GET
path: /
s3hook:
handler: handler.s3hook
events:
- s3: 052a36f5fb9elocalbucketz
event: s3:*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment