AWS Simple Email Service - 需要代码才能将 boto3 与 IAM 配置文件结合使用

use*_*107 0 windows amazon-web-services amazon-ses amazon-iam boto3

我想使用boto3库和用户配置文件访问 Amazon\xe2\x80\x99s SES(简单电子邮件服务)。下面列出了我想要执行的代码,但它不起作用。它给了我一个错误 \xe2\x80\x9cbotocore.exceptions.NoCredentialsError: Unable to locatecredentials\xe2\x80\x9d,我目前可以毫无问题地访问S3服务,所以我知道我的配置文件设置正确,但我不能查找使用配置文件访问 SES 服务的代码。我需要一些指导如何让代码工作。

\n\n

不起作用的SES 代码

\n\n
import boto3\n\nsession = boto3.session.Session(profile_name=\'myprofile\')\nclient = boto3.client(\'ses\',\'us-east-1\')\nresponse = client.list_verified_email_addresses()\n
Run Code Online (Sandbox Code Playgroud)\n\n

当前适用于配置文件的 S3 代码

\n\n
import boto3\n\nsession = boto3.session.Session(profile_name=\'myprofile\')\ns3 = session.resource(\'s3\')\n
Run Code Online (Sandbox Code Playgroud)\n\n

参考:http ://boto3.readthedocs.org/en/latest/reference/services/ses.html

\n

hel*_*loV 5

在您的 SES 代码中,您没有使用通过您的配置文件创建的会话。但在 S3 代码中,您使用会话。当您致电时boto3.client(),它对您的个人资料一无所知。尝试这个:

session = boto3.Session(profile_name='myprofile')
client = session.client('ses','us-east-1')
response = client.list_verified_email_addresses()
Run Code Online (Sandbox Code Playgroud)