Skip to content

Instantly share code, notes, and snippets.

@nazreen
Created April 26, 2019 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazreen/a9225bae114e4cf843daefd4385912a7 to your computer and use it in GitHub Desktop.
Save nazreen/a9225bae114e4cf843daefd4385912a7 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/fikebih
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// When using Lambda Proxy integration on API Gateway, the payload is always string escaped
// the payload is put in event.body, so in your Lambda, the payload can be accessed there
function lambdaPrintName(event) {
const parsedBody = JSON.parse(event.body)
const { name } = parsedBody
// const { name } = event.body
if (name === undefined) throw 'name must be defined'
console.log('Hello, ' + name)
}
const input = {
name: 'Nazreen'
}
function invokePrintNameFromGateway(requestBody) {
const escapedRequest = JSON.stringify(requestBody)
lambdaPrintName({ body: escapedRequest })
}
// invokePrintNameFromGateway(input)
// so that's if the event source is API Gateway
// if the event source is from the sdk instead..
// lambda will expect a params object which contains Payload in it
// it expects stringified Payload for the same security reason
// this Payload will be passed as the event.body to Lambda
const sdkInput = {
name: 'Efim'
}
const sdkPayload = {
body: JSON.stringify(sdkInput)
}
function invokePrintNameFromSdk({ Payload }) {
const eventBody = JSON.parse(Payload)
lambdaPrintName(eventBody)
}
invokePrintNameFromSdk({ Payload: sdkPayload })
</script>
<script id="jsbin-source-javascript" type="text/javascript">// When using Lambda Proxy integration on API Gateway, the payload is always string escaped
// the payload is put in event.body, so in your Lambda, the payload can be accessed there
function lambdaPrintName(event) {
const parsedBody = JSON.parse(event.body)
const { name } = parsedBody
// const { name } = event.body
if (name === undefined) throw 'name must be defined'
console.log('Hello, ' + name)
}
const input = {
name: 'Nazreen'
}
function invokePrintNameFromGateway(requestBody) {
const escapedRequest = JSON.stringify(requestBody)
lambdaPrintName({ body: escapedRequest })
}
// invokePrintNameFromGateway(input)
// so that's if the event source is API Gateway
// if the event source is from the sdk instead..
// lambda will expect a params object which contains Payload in it
// it expects stringified Payload for the same security reason
// this Payload will be passed as the event.body to Lambda
const sdkInput = {
name: 'Efim'
}
const sdkPayload = {
body: JSON.stringify(sdkInput)
}
function invokePrintNameFromSdk({ Payload }) {
const eventBody = JSON.parse(Payload)
lambdaPrintName(eventBody)
}
invokePrintNameFromSdk({ Payload: sdkPayload })
</script></body>
</html>
// When using Lambda Proxy integration on API Gateway, the payload is always string escaped
// the payload is put in event.body, so in your Lambda, the payload can be accessed there
function lambdaPrintName(event) {
const parsedBody = JSON.parse(event.body)
const { name } = parsedBody
// const { name } = event.body
if (name === undefined) throw 'name must be defined'
console.log('Hello, ' + name)
}
const input = {
name: 'Nazreen'
}
function invokePrintNameFromGateway(requestBody) {
const escapedRequest = JSON.stringify(requestBody)
lambdaPrintName({ body: escapedRequest })
}
// invokePrintNameFromGateway(input)
// so that's if the event source is API Gateway
// if the event source is from the sdk instead..
// lambda will expect a params object which contains Payload in it
// it expects stringified Payload for the same security reason
// this Payload will be passed as the event.body to Lambda
const sdkInput = {
name: 'Efim'
}
const sdkPayload = {
body: JSON.stringify(sdkInput)
}
function invokePrintNameFromSdk({ Payload }) {
const eventBody = JSON.parse(Payload)
lambdaPrintName(eventBody)
}
invokePrintNameFromSdk({ Payload: sdkPayload })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment