Bootstrap FreeKB - Amazon Web Services (AWS) - Create public Lambda URL
Amazon Web Services (AWS) - Create public Lambda URL


Creating a Lambda Function that has a public URL that requests can be submitted to is incredibly easy. In the AWS Lambda console, create a Lambda Function.

 

By default, the Lambda Function will not have a URL. Click Create function URL.

 

Since this is just a getting started article, let's go with NONE for authentication for now (we'll update this in a moment) and click Save.

 

And now your Lambda Function has a URL!

 

And on any system that has Internet access, you should be able to request the Lambda URL and get the response. How cool!

~]$ curl https://v5hqtnrafoege4ucolgtc6iiyi0qmjju.lambda-url.us-east-1.on.aws/
"Hello from Lambda!"

 

But what about security? What if your Lambda Function should only be accessible by authenticated users, or only accessible from systems in your Virtual Private Cloud (VPC)?

Let's update the Lambda URL to only be accessible to authenticated IAM users and roles.

 

Now we get forbidden if we request the URL without any sort of authentication.

~]$ curl https://v5hqtnrafoege4ucolgtc6iiyi0qmjju.lambda-url.us-east-1.on.aws/
{"Message":"Forbidden"}

 

One way to authenticate would be to use the Python boto3. Check out my article Invoke Lambda Function using Python boto3.

#!/usr/bin/python3
import boto3

client = boto3.client('lambda')
response = client.invoke(
        FunctionName="my-lambda-function"
        )

print(response['Payload'].read().decode('utf-8'))

.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 2f18e0 in the box below so that we can be sure you are a human.