Last active
February 22, 2021 08:16
-
-
Save apoorvmote/b1067a2261650c4aa8669cc061736a0f to your computer and use it in GitHub Desktop.
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
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 | |
} |
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 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' | |
}) | |
} | |
} |
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
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] | |
}) |
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 latestLayer = LayerVersion.fromLayerVersionAttributes(this, 'latestLayer', { | |
compatibleRuntimes: [Runtime.NODEJS_14_X], | |
layerVersionArn | |
}) |
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 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