sst / ion

❍ — a new engine for SST
https://ion.sst.dev
MIT License
1.34k stars 175 forks source link

Expose HostedZoneLookup helper #214

Open JanStevens opened 4 months ago

JanStevens commented 4 months ago

Hi,

Having a helper that can resolve a provided domainName to a hosted zone ID is extremely helpful, so it would be great to expose this.

Right now I have to import from

import { HostedZoneLookup } from './.sst/platform/src/components/aws/providers/hosted-zone-lookup';

And install 2 additional packages:

@aws-sdk/client-route-53
@aws-sdk/middleware-retry
arpadgabor commented 4 months ago

You don't need to do that, you can use the pulumi aws provider which is provided out of the box:

async run() {
  const zone = await aws.route53.getZone({ name: "your-domain.com" });
}

You don't even need to import anything, you should have it all autocompleted.

JanStevens commented 4 months ago

You don't need to do that, you can use the pulumi aws provider which is provided out of the box:


async run() {

  const zone = await aws.route53.getZone({ name: "your-domain.com" });

}

You don't even need to import anything, you should have it all autocompleted.

Thanks but does that also work when you want to look for a hosted zone without knowing the exact name? Example: I need to find the hosted zone for webhooks.api.staging.domain.com where I might have a hosted zone for staging.domain.com and domain.com. In that case I want to use staging.domain.com.

arpadgabor commented 4 months ago

No I don't think it works like that. But for your use case, if you know the stage name and you are sure there is a Hosted Zone with that stage name, you can do:

const stage = $util.getStack()

const domainPrefix = stage === 'production' ? '' : `${stage}.`

const zone = await aws.route53.getZone({ name: `${domainPrefix}your-domain.com` });

Otherwise, if you indeed need to query for all hosted zones, I think you can use Pulumi to do async tasks, something like:

const result = $util.output((async () => {
      // call to route53 using the sdk
      // filter hosted zones and return the desired zone
      return 'zone'
})())
JanStevens commented 4 months ago

No I don't think it works like that. But for your use case, if you know the stage name and you are sure there is a Hosted Zone with that stage name, you can do:


const stage = $util.getStack()

const domainPrefix = stage === 'production' ? '' : `${stage}.`

const zone = await aws.route53.getZone({ name: `${domainPrefix}your-domain.com` });

Otherwise, if you indeed need to query for all hosted zones, I think you can use Pulumi to do async tasks, something like:


const result = $util.output((async () => {

      // call to route53 using the sdk

      // filter hosted zones and return the desired zone

      return 'zone'

})())

Yes that's basically what HostedZoneLookup does and why I made an issue 😅