'How to call a AWS Lambda outside of AWS
This is a quite basic question, but I was unable to find it out: How can I call a lambda via https without using an EC2 instance or something similar which has to run 24/7. So that I can call my method from an App, via CURL or what every tool which supports http.
I found some references to some Gateway APIs, but I don't know how to call them. Also do I need to setup some access permissions? Can I setup also access control or do I need to implement that within the lambda?
Solution 1:[1]
You can do it either with API or by CLI The API way will be time-consuming, but usually more robust and maintainable.
Solution 2:[2]
AWS doesn't care where your code is running, when you access its APIs.
The service endpoints are all accessible via the Internet.
There's nothing magical about accessing the APIs from "inside," because that isn't what you're doing, in the most logical sense, when you run code on EC2.
Technically speaking, the API requests always go out to the Internet. If you are accessing an AWS service within the same AWS region, your requests still logically go out to the Internet, even though the traffic between your application and the API endpoint never actually leaves the AWS IP infrastructure... but if you have an EC2 instance that can't access the Internet, then it can't access the service API endpoints, either.
(One exception exists if you have an S3 VPC endpoint configured, but this is something you have to configure, and it only allows access to S3 buckets within the same region).
The same code, without modification, should work from inside and outside.
Solution 3:[3]
I assume you connected your API Gateway with your Lambda and the test invocation works as expected. The final step you are missing is the deployment. You have to deploy your API Gateway in order to invoke it from outside. In the API Gateway sections, you click on the "Actions" button and then on "Deploy API". After the deployment, you will receive an URL which you can call via CURL to invoke your Lambda. I hope that helps you further.
Solution 4:[4]
You can also assign a dedicated URL directly to your Lambda without having to use the API Gateway.
https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DaMaill |
Solution 2 | Michael - sqlbot |
Solution 3 | Robert Reiz |
Solution 4 | tjg184 |