Created
May 5, 2019 04:35
-
-
Save Y-Fujikawa/b2c867c912b5bcf000c17e0c6a01f582 to your computer and use it in GitHub Desktop.
LambdaでS3からJSONファイルの内容を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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