cookiecutter-django
cookiecutter-django copied to clipboard
only export AWS creds if defined allowing use of iam role
Description
Allow use of AWS IAM Role for S3 as stated in docs.
Checklist:
- [X] I've made sure that tests are updated accordingly (especially if adding or updating a template option)
- [X] I've updated the documentation or confirm that my change doesn't require any updates
Rationale
The docs state that "it’s safe to remove the AWS_ACCESS_KEY_ID AND AWS_SECRET_ACCESS_KEY from .envs/.production/.django". https://cookiecutter-django.readthedocs.io/en/latest/deployment-with-docker.html?highlight=aws#optional-use-aws-iam-role-for-ec2-instance
When leaving the vars empty, aws cli complains:
$ docker-compose run --rm awscli upload
Creating REDACTED_awscli_run ... done
INFO: Upload the backups directory to S3 bucket {REDACTED}
upload failed: ../backups/backup_2022_08_06T18_05_07.sql.gz to s3://REDACTED/backups/backup_2022_08_06T18_05_07.sql.gz An error occurred (AuthorizationHeaderMalformed) when calling the PutObject operation: The authorization header is malformed; a non-empty Access Key (AKID) must be provided in the credential.
ERROR: 1
When commenting out the vars the upload/download scripts complain:
$ docker-compose run --rm awscli upload
Creating REDACTED_awscli_run ... done
/usr/local/bin/upload: line 16: DJANGO_AWS_ACCESS_KEY_ID: parameter not set
ERROR: 2