3

I have been messing around with AWS lambda today trying some things out. I am currently trying to trigger the function from a url in a browser.

The URL looks similar to this: https://abcdef.execute-api.eu-west-2.amazonaws.com/default/test

As I understand it I can assign a custom domain to my endpoint, but can I also get rid of the path part of the url, so for example:

GET: https://example.com/

GET: https://example.com/somefile.txt

POST: https://example.com/ ['some_post_field' => 'some data']

Will all be passed to my function, or do I need to configure an EC2 instance with NGINX to proxy-pass the requests to lambda?

Any thoughts would be useful.

2 Answers 2

3

There are now a couple different ways you can accomplish this in AWS:

  1. The newest (arguably coolest!) is to use Cloudfront to run your code using their Lambda@Edge service. You can completely customize your URL path and have portions used as variables like any other REST endpoint. You attach your Lambda fn to "behaviour" endpoints which give you full URL control. Its fairly deep and beyond the scope of your question to explain it all here, but read through the docs at the link provided and you'll likely see lots of stuff you like.
  2. Another older, more expensive but more documented method is to use AWS's API Gateway as you have eluded to in your question's tags. It has a great front end console and is easy to connect API endpoints to your Lambda backend logic by attaching them to REST methods. The console helps you "variable-ize" your URL with form field data. This service helps you the most with custom domains to trigger from. Setting up custom domains is a snap in API Gateway. Be sure to use AWS's SSL Certificate Manager for free SSL certs on your custom domain too!

How you specifically setup your endpoints depends on which service you choose. Personally, given your desire to serve up different types of content, I would lean towards CloudFront, and define a "behaviour" URL for your dynamic Lambda content. If the URL request does not match one of your defined behaviours, it defaults to the Cloudfront cache/origin to serve your static assets (somefile.txt). Only matches go to your attached Lambda fn with form data. Very slick!

A lot of example Lambda@Edge fn's are available here.

I have used both and have clients on both now. Lambda@Edge is ridiculously faster and less expensive, BUT is less documented, has a steeper learning curve, and console is not nearly as helpful. I would honestly try both to see which fits your situation and experience level best. Both will get the job done. EC2 is most definitely NOT needed (nor desired perhaps). Hope that helps — good luck!

Sign up to request clarification or add additional context in comments.

Comments

1

Instead of directly exposing the Lambda function via URL, expose it through AWS API Gateway where you can define your own paths and map to a Domain.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.