I am exposing a AWS Lambda function to public HTTP requests by setting up an AWS API Gateway endpoint pointing to it.
There are two parts to this:
I want to do both parts using API calls instead of the web interface. I can do that for the first part using the AWS SDK and AWS CLI.
However, for the second part, I'm stuck. I haven't found a mention of the API Gateway when looking through the AWS SDK for node.js, or the AWS CLI
Is there a way to set up an API Gateway endpoint for a Lambda function, programatically using the AWS API?
Yes, it's possible via AWS's API to set up your Amazon API Gateway endpoints for your AWS Lambda functions.
While the AWS SDK for JavaScript in Node.js and AWS CLI haven't supported Amazon API Gateway yet, you can set up them using Amazon API Gateway REST API without official SDK. In this case, you will probably use these APIs:
You might want to use 3rd party libraries to integrate Amazon API Gateway with AWS Lambda such as jaws-stack/JAWS or r7kamura/fluct.
Yes...it is absolutely possibly. Below is some node.js code that uses the AWS-SDK for node.js. I'm doing a POST here for the method integration. Now there are a few things you'll need. Hope this helps...good luck!
The ResourceId of the Method you're using for the Gateway API
The Gateway API Rest Id
The ARN of the Invoke Role that is able to invoke your Lambda Function
The ARN of the Lambda function you want to integrate.
var AWS = require('aws-sdk');
api = new AWS.APIGateway();
var params = {
httpMethod: 'POST',
resourceId: [YOUR RESOURCE ID],
restApiId: [YOUR REST API ID],
type: 'AWS',
uri: [YOUR LAMBDA FUNCTION ARN],
integrationHttpMethod: 'POST',
credentials : [YOUR INVOKE ROLE ARN]
};
api.putIntegration(params, function (err, data) {
if (err) {
console.log('AWS Error', err);
} else {
console.log('Put Integration Method Created', data);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With