Skip to content

Instantly share code, notes, and snippets.

@franzwong
Last active January 9, 2019 06:58
Show Gist options
  • Save franzwong/bf3c53863ae0546cd6e868b9e811a312 to your computer and use it in GitHub Desktop.
Save franzwong/bf3c53863ae0546cd6e868b9e811a312 to your computer and use it in GitHub Desktop.
HowTo: Create AWS Lambda with Cloudformation
// 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