Skip to content

Instantly share code, notes, and snippets.

@Y-Fujikawa
Created May 5, 2019 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Y-Fujikawa/b2c867c912b5bcf000c17e0c6a01f582 to your computer and use it in GitHub Desktop.
Save Y-Fujikawa/b2c867c912b5bcf000c17e0c6a01f582 to your computer and use it in GitHub Desktop.
LambdaでS3からJSONファイルの内容を取得する
const aws = require('aws-sdk');
aws.config.region = 'ap-northeast-1';
const s3 = new aws.S3();
console.log('Loading function');
exports.handler = async (event, context) => {
var params = {
Bucket: 'sample',
Key: 'sample.json',
};
var response = {};
try {
const data = await s3.getObject(params).promise();
response = {
statusCode: 200,
body: data.Body.toString(),
};
} catch (err) {
console.log('Error:', err);
}
return response;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment