django_aws_utils

Package Contents

Functions

get_ec2_ip() → str

Get the machine’s IP as used by the load balancer.

get_secret(secret_name: str, region_name: str) → str

Gets a secret from AWS Secrets Manager.

django_aws_utils.get_ec2_ip() → str

Get the machine’s IP as used by the load balancer.

The result should be added to ALLOWED_HOSTS to prevent Django from returning HTTP500. For example, in your settings.py:

ALLOWED_HOSTS = [
    get_ec2_ip(),
    "app.example.com"
]

For the time being, this only supports the Metadata Version 1.

Returns

A string containing the instance’s IPv4

django_aws_utils.get_secret(secret_name: str, region_name: str) → str

Gets a secret from AWS Secrets Manager.

It attempts to use the instance or task credentials.

The secret is returned as text, either as the base64 representation if it’s a binary secret or as a json

Parameters
  • secret_name – The name of the secret

  • region_name – The region where the secret is stored

Returns

The secret