How to link to Endpoint URLs in Static Page

I’m evaluating serverless for a little new project that seems to be a perfect match.
I have a simple static website on S3 and a couple of function calls in lambda to execute tasks from this page.

I’m still struggling a bit with things that might be obvious, one of them is:

How do i add the URL of a lambda call in my static site (html/js)?
Adding the full URL of the lambda manually after a deploy and re-uploading the s3 files afterwards seems like the complete opposite of what i would expect.

What is the right way of doing this?

You could use API Gateway to make sure the URL stays the same throughout deploys.
I use API Gateway and a custom subdomain for my API, the URL for each stage stays the same as I am not calling the function directly.

Isn’t that what serverless is already doing when i define the lambda endpoints with their syntax:

So how do i use those URLs from my static page on S3 (also managed by serverless)?
Right now i took the endpoints i got from the output after a serverless deploy and edit them into my javascript file on s3.

Yes, you are right. I hooked up API Gateway to my custom domain name, e.g. api.<your domain>.com. The easiest way to do so is using Route 53 on AWS. Maybe this link can help?

1 Like