Efficient way to map many Lambda functions to Cloudfront custom domain?

Hi All,

I have a static site in an s3 bucket that maps to my-custom-domain.com, and I would like to map many lambda functions to my-custom-domain.com/api/lambda1, my-custom-domain.com/api/lambda2, and so forth. I can do this manually in the Cloudfront ui by creating an origin for each lambda function, referencing the url for the function which Serverless creates at deploy, and then set a behavior. That all works fine.

My question(s): is there a more efficient way to accomplish this? What if I have 50 lambda endpoints? Is there a way to create an origin and set a behavior through serverless.yml and link it to an existing cloudfront distribution? How do you guys handle large numbers of endpoints?

Thanks!

serverless-domain-manager serverless plugin

Thanks @bfieber. I had tried this before, however I was trying to use a domain that already existed and was referenced in a CloudFront distribution. I received this error when running sls create_domain: Error: Failed to create custom domain api.xxxxxxxxxxx.io.

I deleted rt53 records pointing to this domain and removed reference to this domain in CloudFront. Then I re-ran sls create_domain and I saw a new CloudFront distribution in the Serverless Domain Manager Summary after running sls deploy.

Only other thing that seemed confusing was the CloudFront distribution is not visible in the AWS console or through the aws cli. issue #163 tracks this, but I thought I’d mention it if it can save others some research.

This is a great plugin!

@mtocci
Correct.
It’s not displayed because it’s managed by API Gateway. They don’t want us having the ability to muck it up… :wink: