Coder Social home page Coder Social logo

Comments (15)

timoschilling avatar timoschilling commented on May 16, 2024 51

For me this works:

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: subsidy_request_mailer

Parameters:
  DomainName:
    Type: String
    Default: api.example.com
  HostedZoneName:
    Type: String
    Default: example.com. # don't miss the  dot at the end

Resources:

  SendFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: send/
      Handler: app.lambda_handler
      Runtime: nodejs8.10
      Events:
        send:
          Type: Api
          Properties:
            Path: /send
            Method: get

  APIDomainName:
    Type: AWS::ApiGateway::DomainName
    Properties:
      CertificateArn: arn:aws:acm:us-east-1:...:certificate/...
      DomainName: !Ref DomainName

  APIBasePathMapping:
    Type: AWS::ApiGateway::BasePathMapping
    Properties:
      DomainName: !Ref APIDomainName
      RestApiId: !Ref ServerlessRestApi
      Stage: Prod

  APIDomain:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      HostedZoneName: !Ref HostedZoneName
      RecordSets:
      - Name: !Ref DomainName
        Type: A
        AliasTarget:
          DNSName: !GetAtt APIDomainName.DistributionDomainName
          HostedZoneId: Z2FDTNDATAQYW2 # static ID for CloudFront aliases

from serverless-application-model.

praneetap avatar praneetap commented on May 16, 2024 4

@whereisaaron thanks for the feedback. I think it will be really valuable to add this example to the examples folder. Reopening this issue.

from serverless-application-model.

deleugpn avatar deleugpn commented on May 16, 2024 3

I tried @timoschilling snippet, but I get Cannot import certificates for REGIONAL while EDGE is active and I cannot find anything on the internet with this error message.

from serverless-application-model.

deleugpn avatar deleugpn commented on May 16, 2024 3

The solution is to set

EndpointConfiguration:
  Types: 
    - REGIONAL

from serverless-application-model.

bgardella avatar bgardella commented on May 16, 2024 2

Solid example @timoschilling -- saved me a TON of time.

from serverless-application-model.

mhausenblas avatar mhausenblas commented on May 16, 2024 1

@praneetap can we close this issue now with #1144 merged?

from serverless-application-model.

sanathkr avatar sanathkr commented on May 16, 2024

I am afraid not.. AFAIK CloudFormation hasn't supported APIGW custom domains yet. So SAM does not

from serverless-application-model.

frehner avatar frehner commented on May 16, 2024

@sanathkr thanks for the info. I'll just close this for the time being, then.

from serverless-application-model.

lpalbou avatar lpalbou commented on May 16, 2024

@frehner any update on this ?

from serverless-application-model.

frehner avatar frehner commented on May 16, 2024

Iā€™m not working on this at all. You will want to ask one of the maintainers

from serverless-application-model.

lpalbou avatar lpalbou commented on May 16, 2024

@frehner thanks, sorry for the confusion.

@sanathkr any update on the ability to define a custom domain name in SAM or CloudFormation ?

from serverless-application-model.

brettstack avatar brettstack commented on May 16, 2024

RFC for Custom Domain Names #783

from serverless-application-model.

shexbeer avatar shexbeer commented on May 16, 2024

Good question. Please any AWS Guru ?

from serverless-application-model.

sambanks avatar sambanks commented on May 16, 2024

@timoschilling +1 saved me a tonne of time. Is there an example similar to this in the docs anywhere or would it be worth putting in a PR?

from serverless-application-model.

whereisaaron avatar whereisaaron commented on May 16, 2024

@timoschilling your example was the best example I could find all all of the interwebs. I was amazed that your example works. I am sure it saved me a ton of time over working out a workaround for SAM myself. AWS should definitely grab this into the documentation.

The documentation SAM, API Gateway, and github issues, none of them had working examples, just obfuscated discussions about SAM not supporting custom domains, and obscure stuff about EDGE or REGIONAL (behind manual CloudFront). I was amazed SAM didn't have support for custom domains out of the box. Made me wonder if I shouldn't switch from SAM to Serverless!

Some notes to help others who might want to following the same example:

(1) One key point is that the !Ref ServerlessRestApi in @timoschilling's example works because the AWS::Serverless-2016-10-31 transform creates a AWS::ApiGateway::RestApi resource that happens to have that name. That's a pretty brittle assumption, so if you have trouble, check the resources generated by the stack that it still has that name.

(2) Second, there is a tiny bug in @timoschilling's example, where is says:

  HostedZoneName:
    Type: String
    Default: example.com

The zone name has to be a rooted zone name ending in a '.', e.g. example.com.
Otherwise CloudFront will not find the domain.

(2) The CertificateArn: needs to be a us-east-1 certificate regardless of where you are deploying the stack. CloudFront gets all it certs from us-east-1. You might be able to use a regional cert if you switch to a REGIONAL as @deleugpn suggests but I haven't tested that myself.

from serverless-application-model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.