anymail / django-anymail

Django email backends and webhooks for Amazon SES, Brevo (Sendinblue), MailerSend, Mailgun, Mailjet, Postmark, Postal, Resend, SendGrid, SparkPost, Unisender Go and more
https://anymail.dev
BSD 3-Clause "New" or "Revised" License
1.7k stars 130 forks source link

AMAZON_SES_CLIENT_PARAMS not overriding boto3 reading from environment #291

Closed dmwyatt closed 1 year ago

dmwyatt commented 1 year ago

I have the following in my settings because I want to use different credentials for anymail and my other usages of boto3.

ANYMAIL = {
    "AMAZON_SES_CLIENT_PARAMS": {
        "region_name": "us-east-1",
        "aws_access_key_id": env("AWS_SES_ACCESS_KEY"),
        "aws_secret_access_key": env("AWS_SES_SECRET_KEY"),
    }
}

When I call the send_mail management command I get the output below. Note that botocore finds credentials in env vars and the raise exception says I have to specify a region.

I'm sure I'm doing something wrong, but I dunno...

2022-11-16 18:12:17,098 mailer.engine DEBUG    acquiring lock...
2022-11-16 18:12:17,099 mailer.engine DEBUG    acquired.
2022-11-16 18:12:17,239 mailer.engine INFO     sending message 'Verify your email for Honorarium' to kayte.malik@gmail.com
2022-11-16 18:12:17,256 botocore.credentials INFO     Found credentials in environment variables.
2022-11-16 18:12:17,256 botocore.credentials INFO     Found credentials in environment variables.
2022-11-16 18:12:17,290 mailer.engine DEBUG    releasing lock...
2022-11-16 18:12:17,290 mailer.engine DEBUG    released.
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/management/base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/management/base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/mailer/management/commands/send_mail.py", line 28, in handle
    send_all()
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/mailer/engine.py", line 245, in send_all
    connection, action_taken = error_handler(connection, message, err)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/mailer/engine.py", line 146, in handle_delivery_exception
    six.reraise(*sys.exc_info())
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/six.py", line 719, in reraise
    raise value
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/mailer/engine.py", line 233, in send_all
    email.send()
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/mail/message.py", line 298, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/anymail/backends/base.py", line 89, in send_messages
    created_session = self.open()
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/anymail/backends/amazon_ses.py", line 44, in open
    self.client = boto3.session.Session(**self.session_params).client("ses", **self.client_params)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/boto3/session.py", line 299, in client
    return self._session.create_client(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/session.py", line 950, in create_client
    client = client_creator.create_client(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/client.py", line 123, in create_client
    client_args = self._get_client_args(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/client.py", line 466, in _get_client_args
    return args_creator.get_client_args(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/args.py", line 87, in get_client_args
    final_args = self.compute_client_args(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/args.py", line 183, in compute_client_args
    endpoint_config = self._compute_endpoint_config(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/args.py", line 278, in _compute_endpoint_config
    return self._resolve_endpoint(**resolve_endpoint_kwargs)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/args.py", line 381, in _resolve_endpoint
    return endpoint_bridge.resolve(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/client.py", line 566, in resolve
    resolved = self.endpoint_resolver.construct_endpoint(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/regions.py", line 205, in construct_endpoint
    result = self._endpoint_for_partition(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/botocore/regions.py", line 253, in _endpoint_for_partition
    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.
dmwyatt commented 1 year ago

Nevermind, I had the ANYMAIL configuration in the django settings file for the wrong environment. Sorry for the noise.