IOS/Android App Store Redirect with AWS CloudFront Functions and CDK
I recently wanted to setup a link to redirect people who either clicked on a link or scanned a QR code to be taken to their relevant app stores on IOS or Android for my React Native App. I’m sure theres a few websites out there that do this, but I preferred to have it under my domain, and didn’t want to pay for it.
I thought I’d give it a go using CloudFront functions. It was a bit tricky to get setup using CDK but I’m happy with how it turned out, so I thought I’d share in case anyone was looking to setup a similar thing.
You may be thinking, is setting up a whole CDN a bit overkill for a redirect based on a user agent header? Probably. But its not actually that much code , users wont have to wait for a cold-start or experience distance latency, and CloudFront is pay as you go. So why not.
I’m going to be writing the CDK code in Typescript, and I won’t be diving into setting up Route53, or a CDK project as theres plenty of tutorials out there on those topics.
CDK Stack
First thing to note — make sure this stack is deployed in us-east-1 as that’s where CloudFront functions/distributions must be deployed.
First in the CDK stack we want to add something like this: