配置AWS SDK for Java

时间:2012-04-23 18:39:21

标签: java amazon-web-services aws-sdk amazon-ses

配置 AWS SDK for Java (v1.3.8)后,我想通过运行 AWSJavaMailSample 来测试所有内容。

仔细检查以下情况后:

  1. 已注册SES;
  2. 验证了发件人地址并从AWS控制台发送了测试消息;
  3. 拥有生产权限;
  4. https://aws-portal.amazon.com/gp/aws/securityCredentials
  5. accessKeysecretKey添加到 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:75verifyEmailAddress(ses, FROM);来电。


    shashankaholic's comment

    之后更新#1

    我创建了两个新用户:

    1. ses-test ,附加 AmazonSESFullAccess 用户政策
      {"Statement":[{"Effect":"Allow","Action":["ses:*"],"Resource":"*" }]}
    2. ses-smtp-user ,默认 AmazonSesSendingAccess
      {"Statement":[{"Effect":"Allow","Action":"ses:SendRawEmail","Resource":"*"}]}
    3. 我得到同样的回应。

      即使将 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
      

      在这种情况下应使用哪些凭据?

      或者,如何为AWSJavaMailSample配置AWS SDK for Java?


      更新#2:

      问题是我如何在 .properties 文件中声明凭据

      accessKey="ACCESSKEY"; # Java-string-like
      

      而我应该有

      accessKey=ACCESSKEY
      

2 个答案:

答案 0 :(得分:2)

问题是我如何在 .properties 文件中声明凭据

accessKey="ACCESSKEY"; # Java-string-like

而我应该有

accessKey=ACCESSKEY

答案 1 :(得分:1)

您可以从IAM控制台https://console.aws.amazon.com/iam/home验证您的用户凭据和权限。

转到“用户”选项卡,单击“用户检查权限”。您还可以从https://console.aws.amazon.com/ses/home#smtp-settings生成新的SMTP凭据:以防万一。