title: Creating AWS SES SMTP credentials using IAM Role
body: <p>I am trying to use an IAM Role that I have attached to an EC2 instance to generate a set of AWS SES SMTP credentials. However, after using the script given by Amazon to generate the SMTP Password from the Secret_Key of the IAM Role, and using the Access_Key_ID of the IAM Role, when trying to send an email via django.core.mail, I get error <code>(535, b'Authentication Credentials Invalid')</code>.</p>
  <p>This is how I am sending the email:</p>
  <pre><code>#django.core.mail
  EMAIL_USE_TLS = True
  EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com'
  EMAIL_PORT = 587
  EMAIL_HOST_USER = credentials.access_key
  EMAIL_HOST_PASSWORD = SMTP_PASSWORD
  
  send_mail(
      'Subject here',
      'Here is the message.',
      'from@example.com',
      ['to@example.com'],
      fail_silently=False,
  )
  </code></pre>
  <p>And how am I generating the password:</p>
  <pre><code>session = boto3.session.Session()
  credentials = session.get_credentials().get_frozen_credentials()
  region = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document').json()['region']
  SMTP_PASSWORD = smtp_credentials_generate.calculate_key(secret_access_key=credentials.secret_key, region=region)
  </code></pre>
  <p>The SMTP Password generate script is here: <a href="https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html</a>.</p>
  <p>Through some research, I found these links that say you cannot use an IAM Role to use generate SMTP credentials:</p>
  <p><a href="https://serverfault.com/questions/584789/is-it-possible-to-send-email-via-the-amazon-ses-smtp-service-with-a-iam-role-acc">https://serverfault.com/questions/584789/is-it-possible-to-send-email-via-the-amazon-ses-smtp-service-with-a-iam-role-acc</a>
  <a href="https://hector.dev/2015/01/17/sending-e-mail-via-amazon-ses-over-smtp-with-iam-roles.html" rel="nofollow noreferrer">https://hector.dev/2015/01/17/sending-e-mail-via-amazon-ses-over-smtp-with-iam-roles.html</a></p>
  <p>However, Amazons official QA says that it is possible:
  <a href="https://aws.amazon.com/premiumsupport/knowledge-center/ses-create-smtp-credentials/" rel="nofollow noreferrer">https://aws.amazon.com/premiumsupport/knowledge-center/ses-create-smtp-credentials/</a></p>
  <blockquote>
  <p>Important: The IAM user <strong>or role</strong> that you use to create the SMTP credentials...</p>
  </blockquote>
  <p>So is it possible or not? What am I doing wrong?</p>