简体   繁体   中英

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?

您可以使用APICLI 来完成。API 方式将是耗时的,但通常更健壮和可维护。

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM