Just throwing out some more info I have found, not...
# help
r
Just throwing out some more info I have found, not sure if there is a better place to share this stuff... but in reference to https://serverless-stack.slack.com/archives/C01JG3B20RY/p1642141454001700 and @Lukasz K maybe this helps with the request you mentioned you sent in? If you want to create a APIgV2 (httpAPI) and connect it to a domain name but you do not want to use Route53, or maybe you do but you want to merge separate APIs with at the DomainName level, you can use the following. Just to be clear the merging would be if you have
ApiA
(xxxyyy.execute-api.region.amazonaws.com) and
ApiB
(aaabbb.execute-api.region.amazonaws.com) and you want to end up with
<http://api.example.com/v1/apia|api.example.com/v1/apia>
and
<http://api.example.com/v1/api|api.example.com/v1/api>
. This could be a much less costly solution then an edge lambda or worker to change requests. I'll throw the code in the thread to not fill up the room here.
Copy code
import { DomainName } from '@aws-cdk/aws-apigatewayv2-alpha'
    import { Certificate, CertificateValidation } from 'aws-cdk-lib/aws-certificatemanager'

    const domain = new DomainName(this, 'APIDomain', {
      domainName: `<http://xxx.example.com|xxx.example.com>`,
      certificate:  new Certificate(this, 'MyCert', {
        domainName: '<http://xxx.example.com|xxx.example.com>',
        validation: CertificateValidation.fromDns(),
      }),
    })

    const myAPI = new Api(this, 'myAPI', {
      defaultFunctionProps: {
        srcPath: 'src/api',
      },
      routes: {
        'GET /example': 'example.get'
      },
    })

    new ApiMapping(this, 'AuthAPIMapping', {
      api: myAPI.httpApi,
      domainName: domain,
      apiMappingKey: `custom/path`,
    })
@thdxr any chance the Api construct
customDomain
could add this? maybe a
isExternalDomain
like static sites, to skip Route53, and options to switch to mapping? Would be nice as it handles certs well already.
f
Hey @Ross Gerbasi r u looking for something like this?
Copy code
const myAPI = new Api(this, 'myAPI', {
  customDomain: {
    domainName: "<http://xxx.example.com|xxx.example.com>",
    isExternalDomain: true,
    certificate: new Certificate(this, 'MyCert', {
      domainName: '<http://xxx.example.com|xxx.example.com>',
      validation: CertificateValidation.fromDns(),
    }),
    path: "custom/path",
  },
  ...
})
Note that, you’d have to provide a certificate, SST can’t auto create a cert for you as it cannot be auto-validated.
r
I think so right? thats what i had kinda mocked up., However thje API construct does some cert magic already. no chance we can reuse that
maybe customDomain could also just take the domain itself as a reference? so just like
Copy code
domainName: refToDomainName,
path: "custom/path"
Essentially abstract out the mapping part i guess, in order to share a domain across apis
f
domainName: refToDomainName,
path: “custom/path”
That should work already
r
oh really? doesntthat still create a host zone though?
maybe its just missing
isExternalDomain
then? to opt out of the hostzone stuff?
If youre able to give it a ref like that then the long for custom syntax is less important. Can always just create a DomainName in the stack and pass it in. making it inline is not super priority. the zone it really the more annoying part. As I am not using route53 at all
f
If you pass in a
refToDomainName
, SST will not try to create anything in Route 53, it should work i think.
Alright I will change a few things around here and see if i get the same result. thanks a lot! I guess the only other config option worth considering is adding
isExternalDomain
and allowing
domainName
to be a string. Then having the construct build up the APiGateway domain with the path, instead of passing in a
DomainName
Not a big deal for me as I need to share my
DomainName
anyway. but maybe for someone that just has a single api they wanna throw up on a domain but don't want route53. They can obviously create the domain themselves, but if the construct could hide some complexity of certs maybe that would be helpful?
Just switched over, works great. thanks alot!
f