Last active
January 9, 2023 04:52
-
-
Save harisrozak/c1d61a5989e242ed8ea1fac71bf5315a to your computer and use it in GitHub Desktop.
Sample AWS Lambda code with NodeJS
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
export const handler = async (event) => { | |
const body = JSON.parse(event.body); | |
const queryStrings = event.queryStringParameters; | |
let capitalCity = 'none'; | |
const message = !!queryStrings?.message ? queryStrings.message : 'Hello'; | |
switch (body.nation) { | |
case 'Indonesia': | |
capitalCity = 'Jakarta'; | |
break; | |
case 'US': | |
capitalCity = 'Washington, D.C.'; | |
break; | |
case 'Germany': | |
capitalCity = 'Berlin'; | |
break; | |
default: | |
// code | |
} | |
const response = { | |
statusCode: 200, | |
body: { | |
nation: body.nation, | |
capital: capitalCity, | |
message: message, | |
} | |
}; | |
return response; | |
}; |
Sample POST target endpoint with Function URL:
https://qwertyjr5b2tm245h3fp2broki0djdda.lambda-url.us-west-2.on.aws/?message=HelloWorld
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The event JSON will be: