1

I'm fairly new to Cloudfront ( AWS in general ), and looking set up a behaviour such that any requests that is for example

test.com/api/*

goes to an existing api that we also own, except it's on a seperate domain, e.g.

staging.test.com/api

Is this an allowed behaviour? I probably will need to allow for this the receiving API in CORS but just looking for how to set this up as a behaviour in Cloudfront.

I have tried using lambda functions along with the route

e.g.


    
    var response = {
        statusCode: 302,
        statusDescription: 'Found',
        headers:
            { "location": { "value": "https://staging.test.com.au/api/" + redirectPath } }
        }

    return response;

That doesn't seem to be working.

So was just wondering what is the correct way of going about this, I can only find references on using an API gateway instead which isn't what I want.

1 Answer 1

0

You can do it by using origin and behavior. Define origin for and staging.test.com/api and add new behavior with path pattern as /api/*.

Details: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html?icmpid=docs_cf_help_panel#DownloadDistValuesPathPattern

2
  • Heya thanks, we ended up solving this, basically the way you suggested but we had a load balancer that sat in front of our API so we ended up pointing it to that as our origin which worked.
    – Ben Perram
    Nov 27, 2022 at 22:57
  • Great, I'm glad it worked out for you. :) Nov 28, 2022 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .