配置AWS SDK for Java (v1.3.8) 后,我想通过运行他们的AWSJavaMailSample来测试所有内容。
在仔细检查以下内容是否正确后:
- 报名参加 SES;
- 验证发件人地址并从 AWS 控制台发送测试消息;
- 拥有生产权限;
- 从https://aws-portal.amazon.com/gp/aws/securityCredentials
accessKey
将和添加secretKey
到AwsCredentials.properties文件
我得到一个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)
哪里AWSJavaMailSample.java:75
来的verifyEmailAddress(ses, FROM);
电话。
更新 #1,遵循shashankaholic 的评论
我创建了两个新用户:
- ses-test,附加AmazonSESFullAccess用户策略
{"Statement":[{"Effect":"Allow","Action":["ses:*"],"Resource":"*" }]}
- ses-smtp-user,默认为 AmazonSesSendingAccess
{"Statement":[{"Effect":"Allow","Action":"ses:SendRawEmail","Resource":"*"}]}
我得到了同样的回应。
即使在将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
在这种情况下应该使用什么凭据?
或者应如何配置适用于 Java 的 AWS 开发工具包以使 AWSJavaMailSample 正常工作?
更新#2:
问题是我如何在.properties文件中声明凭据
accessKey="ACCESSKEY"; # Java-string-like
相反,我应该有
accessKey=ACCESSKEY