2

I am trying to create a lambda function using SAM, however I can't work out how to add a custom domain to it. Do I need to add a whole ApiGateway to my CloudFormation template just to change the domain or is there is an easier way?

My domain is in Route53 and I have a certificate for it in ACM.

My template is currently as follows:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.
Resources:
  ExampleWebApi:
    Type: AWS::Serverless::Function
    Properties:
      Handler: Example.WebApi::Example.WebApi.LambdaEntryPoint::FunctionHandlerAsync
      Runtime: dotnetcore2.1
      CodeUri: ''
      MemorySize: 128
      Timeout: 10
      Role: null
      Policies:
      - AWSLambdaFullAccess
      Environment:
        Variables: {}
      Events:
        PutResource:
          Type: Api
          Properties:
            Path: "/{proxy+}"
            Method: ANY
Karl Green
  • 260
  • 1
  • 4
  • 11
  • How are you calling your Lambda function. I don't see the relevance of a domain name if you are calling the Labda via the AWS API... Only relevant if you are using API Gateway, in which case you are already using APIG, so custom domain name can be added to the APIG. – Matt D Nov 19 '18 at 00:20
  • I'd like to call it directly from a mobile app, which I can already do via the api gateway that is created. However if I delete the stack and recreate it for any reason the url changes which is why I'd like to put my own domain in front of it which won't change. I'm aware that I can go into the console and manually add my domain to the gateway but I am unsure how to do it in the template – Karl Green Nov 19 '18 at 08:51
  • 1
    Does this help?: https://github.com/awslabs/serverless-application-model/issues/40#issuecomment-411316776 – Matt D Nov 19 '18 at 13:20
  • Got it sorted now, that helped me a lot thank you! – Karl Green Nov 19 '18 at 23:56

1 Answers1

1

Yes, you need to use API Gateway in order to define a custom domain for a lambda function.

bwest
  • 9,182
  • 3
  • 28
  • 58