Skip to content

Instantly share code, notes, and snippets.

@mich-cook
Created January 21, 2021 04:33
Show Gist options
  • Save mich-cook/2d993fedb56c8ffc23c1ed0a8ed2f9ba to your computer and use it in GitHub Desktop.
Save mich-cook/2d993fedb56c8ffc23c1ed0a8ed2f9ba to your computer and use it in GitHub Desktop.
Minimal working version of call to AWS lambda to keep handy so I can screw up the one on my machine, er, I mean experiment with it.
const AWS = require("aws-sdk");
// Get soopur seekrit vars from .env file.
require("dotenv").config(); // could test response, but out of scope for simplicity
const REGION = process.env.REGION;
const IDENTITY_POOL_ID = process.env.IDENTITY_POOL_ID;
const FUNCTION_NAME = process.env.FUNCTION_NAME;
// Init cognito
AWS.config.region = REGION;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
"IdentityPoolId": IDENTITY_POOL_ID
});
// Init params to pass to lambda function
const params = {
"FunctionName" : FUNCTION_NAME,
"InvocationType" : "RequestResponse",
"LogType" : "None"
};
// Init lambda
const lambda = new AWS.Lambda({ "apiVersion": "2015-03-31" });
// Call the function and see what happens.
lambda.invoke(params, function(err, data) {
if (err) {
console.log(err);
} else {
console.log(JSON.parse(data.Payload).body);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment