Serving a Lambda function via a custom domain

My problem

I have the basic hello world function deployed at the https://<something>.execute-api.eu-central-1.amazonaws.com/dev.

I would like to have the same function deployed in my own subdomain, say m/-sub.domain.com. The subdomain is defined in Route53, but I did not find a straightforward way to map it to the lambda function using serverless.

What have I tried

I’ve Googled quite a bit and tried some solutions (especially this one), by adding the following:

environment:
  DomainName: <my-sub.domain.com>
  stageName: whatever                       # What does this mean?

resources:
Resources:
    pathmapping:
        Type: AWS::ApiGateway::BasePathMapping
        Properties:
            BasePath: oauth2
            DomainName: ${self:vars.domainName}
            RestApiId: 
                Ref: ApiGatewayRestApi
            Stage: ${self:vars.stage}

But ended up with:

 Serverless Warning --------------------------------------

  A valid service attribute to satisfy the declaration 'self:vars.domainName' could not be found.


 Serverless Warning --------------------------------------

  A valid service attribute to satisfy the declaration 'self:vars.stage' could not be found.

I am not sure what is the stage variable, and why is the domainName unreadable by the deployment tool.

Appreciate any help,
Adam

I think the answer is simply that you’ve used the wrong reference in your config.

You’ve defined the domain name as DomainName under environment, but you are trying to refer to it as though it is under vars. So where you have ${self:vars.domainName} you should have ${self:environment.DomainName} (note that you defined it with an initial upper case, so you should use an initial upper case when you refer to it; or change it all over to initial lower case).

The stage is related to the software develop-test-release cycle, and would normally be things like “development” (or “dev”), “staging”, “test” (or “testing”), “uat” (user acceptance testing), and “production”. If you don’t know what it is, your provider will give you a default value, so where you have ${self:vars.domainName} you could just put ${self:provider.stage} and then you don’t need to define stage under environment.