handler = async (req, res, context) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "PUT, GET, OPTIONS");
if (req.method === 'OPTIONS') res.status(200).end();
const aws_creds = context.secrets['tomlarkworthy_aws'];
AWS.config.credentials = new AWS.ChainableTemporaryCredentials({
masterCredentials: parseCreds(aws_creds)
});
const key = req.url.substring(1);
if (req.method == "GET") {
const s3res = await new AWS.S3().getObject({
Bucket: 'tomlarkworthy-access-aws',
Key: key
}).promise().catch((err) => res.status(404).send(err.message))
res.send(s3res.Body.toString('utf-8'))
} else if (req.method == "PUT") {
const s3res = await new AWS.S3().putObject({
Bucket: 'tomlarkworthy-access-aws',
Key: key,
Body: req.body
}).promise()
res.end()
}
}