Skip to content

Instantly share code, notes, and snippets.

@apoorvmote
Last active February 22, 2021 08:16
Show Gist options
  • Save apoorvmote/b1067a2261650c4aa8669cc061736a0f to your computer and use it in GitHub Desktop.
Save apoorvmote/b1067a2261650c4aa8669cc061736a0f to your computer and use it in GitHub Desktop.
exports.discountForProduct = (productId) => {
const products = [
{
productId: '1',
discount: '10%'
},
{
productId: '2',
discount: '20%'
},
{
productId: '3',
discount: '30%'
}
]
const item = products.find(element => element.productId === productId)
return item.discount
}
const uuid = require('uuid/v4')
const { discountForProduct } = require('./discount')
exports.handler = async(event) => {
const { productId } = event.queryStringParameters
return {
statusCode: 200,
body: JSON.stringify({
transactionId: uuid(),
discount: discountForProduct(productId),
message: 'from lambda one'
})
}
}
new Function(this, 'oneFn', {
runtime: Runtime.NODEJS_14_X,
code: Code.fromAsset(`${__dirname}/../lambda-fns/one/deployment.zip`),
handler: 'index.handler',
layers: [latestLayer]
})
new Function(this, 'twoFn', {
runtime: Runtime.NODEJS_14_X,
code: Code.fromAsset(`${__dirname}/../lambda-fns/two/deployment.zip`),
handler: 'index.handler',
layers: [latestLayer]
})
const latestLayer = LayerVersion.fromLayerVersionAttributes(this, 'latestLayer', {
compatibleRuntimes: [Runtime.NODEJS_14_X],
layerVersionArn
})
const layer = new LayerVersion(this, 'uuidLayer', {
code: Code.fromAsset(`${__dirname}/../lambda-fns/layer/deployment.zip`),
compatibleRuntimes: [ Runtime.NODEJS_14_X],
description: 'uuid package and discount for product'
})
layer.addPermission('layerPermission', {
accountId: account
})
new CfnOutput(this, 'layerVersionArn', {
value: layer.layerVersionArn
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment