首页 > 解决方案 > AWS SES 在本地计算机上运行

问题描述

我编写了一个使用 aws ses 发送电子邮件的系统(代码如下)。这在网站上运行良好,但我也很惊讶它似乎可以在我的本地计算机上运行。我想知道的是,如果我不小心为我的 aws 帐户提供了全球发送电子邮件的能力,或者我的本地电脑是否以某种方式登录到 aws,以便它仍然可以发送电子邮件。如果是这种情况,我如何注销以确保它是安全的?或者我如何确保它只是可以发送电子邮件的网站。

谢谢

标记

# Form is valid, get the data from the form
sender_email = form.cleaned_data['form_email']

# Generate the new email message
strNewSubject = "CONTACT FROM sendemail DJANGO APP"
strNewMessage = f"Hello from a random user of sendemail Django App."

# Create a new SES resource and specify a region.   SES is in
# eu-west-1 NOT eu-west-2
client = boto3.client('ses', region_name="eu-west-1")

tmpDestination = {'ToAddresses':
                    ["blah@something.com", ], }
tmpMessage = {
        'Body': {
            'Text': {
                'Charset': "UTF-8",
                'Data': strNewMessage,
            },
        },
        'Subject': {
            'Charset': "UTF-8",
            'Data': strNewSubject,
        },
    }
# Provide the contents of the email.
response = client.send_email(
    Destination=tmpDestination,
    Message=tmpMessage,
    Source="srcaddress@gmail.com"
)

# Email sent and no error's
return True

标签: amazon-web-servicesamazon-ses

解决方案


这只是一些额外的点,可能会帮助将来有这种担忧的人,它扩展了 jordanm 的答案,这非常有帮助:

您可以使用以下方法获取当前可用配置文件的列表:

aws configure list-profiles

您可以使用以下方法列出您当前的个人资料:

aws configure list

您可以使用以下方法获取有关特定配置文件的信息:

aws configure list --profile profile_name

假设 .aws 已在您的用户目录 (~) 中设置,您可以使用以下命令查看配置和凭证文件:

cat ~/.aws/config

cat ~/.aws/credentials

然后,您可以使用 --profile 参数或 AWS_PROFILE 环境变量指定您正在使用的配置文件:

aws ec2 describe-volumes --profile dev
export AWS_PROFILE=dev

资料来源:
如何查看 CLI 的默认配置文件?.
https://www.thegeekstuff.com/2019/03/aws-configure-examples/


推荐阅读