Reputation: 6469
I currently have an api called “cms-api”, which contains a dynamodb scan function in it.
getOrganization.js
'use strict'
const AWS = require('aws-sdk');
exports.handler = async function (event, context, callback) {
const documentClient = new AWS.DynamoDB.DocumentClient();
let responseBody = "";
const params = {
TableName : "Organization"
};
try{
const data = await documentClient.scan(params).promise();
}catch(err){
responseBody = `Unable to get Organization: ${err}`;
}
}
“Organization” Table has below attributes
------------------------------------------
Id isActive name
1 true tim
2 false tom
3 true ken
4 true joe
------------------------------------------
Later, I create another api in api gateway called web-api,
I want to use the same lambda function getOrganization.js in my resource.
But the getOrganization.js should only return the data with isActive = true.
Is it possible? Or should I create a new lambda function every time?
Attached my consideration before.
should I create Public api based on the current internal api
Upvotes: 0
Views: 180
Reputation: 238299
Generally, you would consider using stage variables in your API gateway. They allow you:
You can also use stage variables to pass configuration parameters to a Lambda function through your mapping templates. For example, you might want to reuse the same Lambda function for multiple stages in your API, but the function should read data from a different Amazon DynamoDB table depending on which stage is being called. In the mapping templates that generate the request for the Lambda function, you can use stage variables to pass the table name to Lambda.
Upvotes: 2