为 Java 配置 AWS 开发工具包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10286291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuring the AWS SDK for Java
提问by Marius Butuc
After configuring the AWS SDK for Java(v1.3.8), I want to test everything by running their AWSJavaMailSample.
配置AWS SDK for Java(v1.3.8) 后,我想通过运行他们的AWSJavaMailSample来测试所有内容。
After double checking that the following are true:
仔细检查以下情况后:
- signed up for SES;
- verified a sender address and sent test message from the AWS console;
- having production access;
- added the
accessKey
and thesecretKey
to the AwsCredentials.propertiesfile, from https://aws-portal.amazon.com/gp/aws/securityCredentials
- 注册了 SES;
- 验证发件人地址并从 AWS 控制台发送测试消息;
- 具有生产访问权;
- 添加
accessKey
和secretKey
到AwsCredentials.properties文件,来自https://aws-portal.amazon.com/gp/aws/securityCredentials
I get an InvalidClientTokenId: the AWS Access Key ID provided does not exist in the AWS records.
我收到InvalidClientTokenId:AWS 记录中不存在提供的 AWS 访问密钥 ID。
[AmazonSimpleEmailService]$ java AWSJavaMailSample
Exception in thread "main" Status Code: 403, AWS Service: AmazonSimpleEmailService, AWS Request ID: 6db92cf8-8d69-11e1-b872-d1f99982ef22, AWS Error Code: InvalidClientTokenId, AWS Error Message: The security token included in the request is invalid
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:552)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:289)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:170)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.invoke(AmazonSimpleEmailServiceClient.java:479)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.listVerifiedEmailAddresses(AmazonSimpleEmailServiceClient.java:214)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.listVerifiedEmailAddresses(AmazonSimpleEmailServiceClient.java:410)
at AWSJavaMailSample.verifyEmailAddress(AWSJavaMailSample.java:155)
at AWSJavaMailSample.main(AWSJavaMailSample.java:75)
Where AWSJavaMailSample.java:75
is the verifyEmailAddress(ses, FROM);
call.
哪里AWSJavaMailSample.java:75
是verifyEmailAddress(ses, FROM);
电话。
Update #1, following shashankaholic's comment
更新 #1,遵循shashankaholic 的评论
I've created two new users:
我创建了两个新用户:
- ses-test, attached AmazonSESFullAccessuser policy
{"Statement":[{"Effect":"Allow","Action":["ses:*"],"Resource":"*" }]}
- ses-smtp-user, with the default AmazonSesSendingAccess
{"Statement":[{"Effect":"Allow","Action":"ses:SendRawEmail","Resource":"*"}]}
- ses-test,附加AmazonSESFullAccess用户策略
{"Statement":[{"Effect":"Allow","Action":["ses:*"],"Resource":"*" }]}
- ses-smtp-user,使用默认的AmazonSesSendingAccess
{"Statement":[{"Effect":"Allow","Action":"ses:SendRawEmail","Resource":"*"}]}
And I get the same response.
我得到了同样的回应。
Even after attaching AdministratorAccessto ses-smtp-user{"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]}
still same response:
即使将AdministratorAccess附加到ses-smtp-user 后,{"Statement":[{"Effect":"Allow","Action":"*","Resource":"*"}]}
仍然有相同的响应:
Exception in thread "main" Status Code: 403,
AWS Service: AmazonSimpleEmailService,
AWS Request ID: [...],
AWS Error Code: InvalidClientTokenId,
AWS Error Message: The security token included in the request is invalid
What credentials should be used in this case?
在这种情况下应该使用什么凭据?
Or how should the AWS SDK for Java be configured for AWSJavaMailSample to work?
或者应如何配置适用于 Java 的 AWS 开发工具包以使 AWSJavaMailSample 工作?
Update #2:
更新#2:
the problem was how I was declaring the credentials in the .propertiesfile
问题是我如何在.properties文件中声明凭据
accessKey="ACCESSKEY"; # Java-string-like
when instead I should have had
什么时候我应该有
accessKey=ACCESSKEY
采纳答案by shashankaholic
You can verify your User Credentials and privileges from IAM console https://console.aws.amazon.com/iam/home.
您可以从 IAM 控制台https://console.aws.amazon.com/iam/home验证您的用户凭证和权限。
Go to users tab, click on user check privileges. You can also generate new SMTP credentials from https://console.aws.amazon.com/ses/home#smtp-settings: in case.
转到用户选项卡,单击用户检查权限。您还可以从https://console.aws.amazon.com/ses/home#smtp-settings生成新的 SMTP 凭证:以防万一。
回答by Marius Butuc
The problem was how I was declaring the credentials in the .propertiesfile
问题是我如何在.properties文件中声明凭据
accessKey="ACCESSKEY"; # Java-string-like
when instead I should have had
什么时候我应该有
accessKey=ACCESSKEY