Last active
January 9, 2019 06:58
-
-
Save franzwong/bf3c53863ae0546cd6e868b9e811a312 to your computer and use it in GitHub Desktop.
HowTo: Create AWS Lambda with Cloudformation
This file contains hidden or 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
// For simplicity, error handling is not included | |
const axios = require('axios') | |
const AWS = require('aws-sdk'); | |
const region = process.env['AwsRegion'] | |
AWS.config.update({region}); | |
const url = process.env['ExchangeRateURL'] | |
const bucket = process.env['S3Bucket'] | |
const objectKey = process.env['S3ObjectKey'] | |
const cacheMaxAge = process.env['S3ObjectCacheMaxAge'] | |
exports.getExchangeRate = async (event) => { | |
const res = await axios.get(url) | |
const params = { | |
Body: JSON.stringify(res.data), | |
Bucket: bucket, | |
Key: objectKey, | |
ContentType: 'application/json', | |
CacheControl: 'max-age=' + cacheMaxAge | |
} | |
const s3 = new AWS.S3(); | |
await s3.putObject(params).promise() | |
return res.data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment