3

I have successfully set up a Django app following a Zappa tutorial I found. However, the problem is that Zappa deploys my app to the location:

 https://some-aws-address/devel

where "devel" is the name of my particular Zappa deployment.

The problem with this is that, at this position, I have pages that have links on them beginning with a '/' that map to:

 https://some-aws-address/ 

and not (as I would want):

https://some-aws-address/devel 

For example, in one of my template files I have a link on an image:

<a href="/"><img src="{% static 'images/main/ryzosens-logo-white-background.png' %}"></a>

where the href="/" always maps to https://some-aws-address/

I don't want to have to do some hack to get my root URLS to map to https://some-aws-address/devel, so the question is:

What must I have in my Django settings (or elsewhere) so that my URL root '/' maps to the HTTP endpoint that Zappa creates?

Many thanks in advance!

Hayden Eastwood
  • 928
  • 2
  • 10
  • 20
  • 1
    Have a look at the mappings of the routes in API gateway – Brian Destura Aug 05 '21 at 00:33
  • I don't believe there are settings in Zappa to get rid of the stage suffix; that's required in AWS API Gateway rest endpoints. So, I set up a Cloudfront distribution and used a Cloudfront function to solve the same issue for my Zappa deployed Flask app: https://stackoverflow.com/questions/69504366/use-cloudfront-to-remove-stage-from-custom-domain-url/69545281#69545281 – Vee Oct 12 '21 at 18:50

1 Answers1

1

The URL suffix is an API Gateway convention: it automatically appends the mandatory stage name to the URL.

I don't think there is an API Gateway or Zappa parameters to change it.

It's recommended to use a custom domain and a custom subdomains for each stage. Thus you can choose a user-friendly URL that matches your needs.

You can also update your STATIC_URL to include the stage. One way to do it is to add the stage as an environment variable and write something like this in your settings.py:

STATIC_URL = os.environ.get("STAGE") + "/static/"

Although I recommend to use a custom domain so you have more control.

Antoine
  • 130
  • 2
  • 12
  • So I had the same issue as the OP and used a mapped my API to a custom domain name via API Gateway. Is there any way I can achieve the same result via Cloudfront instead of API Gateway? – Vee Oct 08 '21 at 19:29
  • You might want to use a custom domain name in Cloudfront the same way you did for API Gateway. – Antoine Oct 12 '21 at 13:22
  • Thanks, Antoine. I have a custom domain name in Cloudfront but the issue was that my distribution was pointing to an API Gateway endpoint that contained a URL suffix which was breaking the links to assets stored in subfolders. I ended up implementing using Cloudfront functions to solve the problem: https://stackoverflow.com/questions/69504366/use-cloudfront-to-remove-stage-from-custom-domain-url/69545281#69545281 – Vee Oct 12 '21 at 18:48