简体   繁体   English

如何在调用 SES listcontacts 时修复 AWS 403 错误“检查您的 AWS 秘密访问密钥和签名方法”

[英]How to fix AWS 403 error "Check your AWS Secret Access Key and signing method" when calling SES listcontacts

I have been stuck for about the past 6 hours at this point I'm thinking the only reasonable explanations are that this is a AWS SDK bug or the error message is wrong.在这一点上,我已经卡住了大约 6 个小时,我认为唯一合理的解释是这是一个 AWS SDK 错误或错误消息是错误的。

I am using SESv2 class from the AWS SDK in a JAVA SpringBoot app and attempting to manage various details of my SES (Simple Email Service) account. I am using SESv2 class from the AWS SDK in a JAVA SpringBoot app and attempting to manage various details of my SES (Simple Email Service) account.

import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.*;

I have created an IAM user, created security credentials, set them up using multiple different methods as described here guid to credentials environment I've given full access to SES to this IAM role user.我已经创建了一个 IAM 用户,创建了安全凭证,并使用多种不同的方法设置它们,如此处所述guid to credentials environment我已向此 IAM 角色用户授予了对 SES 的完全访问权限。 I then wrote some code and I was able to do all of the following,然后我写了一些代码,我能够做以下所有事情,

  • Create a contact list创建联系人列表
  • Delete a contact list删除联系人列表
  • Create contact创建联系人
  • Create a Topic in a contact list在联系人列表中创建主题
  • Send an email发送 email

However, for some unknown reason when I go to test a function I wrote to get a list of contacts so I can test sending an email to multiple contacts I get the following 403 error message,但是,由于某些未知原因,当我 go 测试 function 时,我写了一个联系人列表,以便我可以测试向多个联系人发送 Z0C83F57C786A0B4A39EFAB23731C47EBCZ,我收到以下错误消息

The request signature we calculated does not match the signature you provided.我们计算的请求签名与您提供的签名不匹配。 Check your AWS Secret Access Key and signing method.检查您的 AWS 秘密访问密钥和签名方法。 Consult the service documentation for details.有关详细信息,请参阅服务文档。

I've verified the credentials are correct.我已验证凭据是正确的。 I have created a new set of credentials and made the old set inactive.我创建了一组新的凭据并使旧组处于非活动状态。 No dice, all the functions listed above still work however the listContacts in the SesV2Client class still fails with the same error.没有骰子,上面列出的所有功能仍然有效,但是listContacts中的SesV2Client仍然失败并出现相同的错误。 As you can see below I even bypassed the env variables and just hardcoded the key and secret to pull out all the stops, still fails.正如你在下面看到的,我什至绕过了 env 变量,只是硬编码了密钥和秘密来拉出所有的停止,仍然失败。 In the function that fails, I've gone over and over the values im passing in they are valid and exist 100% because as I said I can make the other calls in the list above to verify the topics and contact list exists.在失败的 function 中,我反复检查了传入的值,它们是有效的并且 100% 存在,因为正如我所说,我可以在上面的列表中进行其他调用来验证主题和联系人列表是否存在。

private List<Contact> listContactsForSiteUpdatesMailingList() {
try (SesV2Client client = SesV2Client.builder()
            .region(Region.US_EAST_1)
            .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
            .build()){

        TopicFilter topicFilter = TopicFilter.builder().topicName(TOPIC_SITE_UPDATES).useDefaultIfPreferenceUnavailable(true).build();
        ListContactsFilter listContactsFilter = ListContactsFilter.builder().topicFilter(topicFilter).filteredStatus(SubscriptionStatus.OPT_IN).build();
        ListContactsRequest listContactsRequest = ListContactsRequest.builder()
                .contactListName(CONTACT_LIST).filter(listContactsFilter).build();

        ListContactsResponse listContactsResponse = client.listContacts(listContactsRequest);

        return listContactsResponse.contacts();

    } catch (Exception ex) {
        System.out.println("The email was not sent. Error message: "
                + ex.getMessage());
        return null;
    }
}

Whats going on here and how can I get to the bottom of this error?这是怎么回事,我怎样才能找到这个错误的根源?

EDIT: Looking at AWS Console Users>Access Management and then looking at the user a created I can even verify that there was "programmatic access"编辑:查看 AWS 控制台用户>访问管理,然后查看创建的用户,我什至可以验证是否存在“程序访问” 在此处输入图像描述

An example of accessing a ContactList with no issues没有问题地访问 ContactList 的示例在此处输入图像描述

EDIT 2: My SES account is currently sandboxed.编辑 2:我的 SES 帐户目前是沙盒。 I just wanted to mention the question is this possibly happening because of that?我只是想提一个问题,这可能是因为这个而发生的吗? Grasping at straws here.在这里抓住稻草。

I was able to reproduce your issue.我能够重现您的问题。 I created a list and added a contact.我创建了一个列表并添加了一个联系人。 Both worked.两者都有效。 However, when i executed listContacts , I got this error:但是,当我执行listContacts时,出现此错误:

在此处输入图像描述

This looks like a bug.这看起来像一个错误。 To address this, open a Github issue on the SDK Java Github here:要解决此问题,请在此处打开 SDK Java Github 上的 Github 问题:

https://github.com/aws/aws-sdk-java https://github.com/aws/aws-sdk-java

This is confirmed as a bug in the AWS SDK.这被确认为 AWS SDK 中的一个错误。 To get around this you can use the async client like so为了解决这个问题,您可以像这样使用异步客户端

 SesV2AsyncClient client = SesV2AsyncClient.builder()
                    .region(Region.US_EAST_1)
                    .build())
        TopicFilter topicFilter = TopicFilter.builder().topicName(TOPIC_SITE_UPDATES).useDefaultIfPreferenceUnavailable(true).build();
        ListContactsFilter listContactsFilter = ListContactsFilter.builder().topicFilter(topicFilter).filteredStatus(SubscriptionStatus.OPT_IN).build();
        ListContactsRequest listContactsRequest = ListContactsRequest.builder()
                .contactListName(CONTACT_LIST).filter(listContactsFilter).build();

        CompletableFuture<ListContactsResponse> listContactsResponseCompletableFuture = client.listContacts(listContactsRequest);
        ListContactsResponse listContactsResponse = listContactsResponseCompletableFuture.get();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取 AWS 访问和密钥 - Fetch AWS Access And Secret Key AWS S3:我们计算出的请求签名与您提供的签名不匹配。 检查您的密钥和签名方法 - AWS S3: The request signature we calculated does not match the signature you provided. Check your key and signing method 如何在Java中为inMemory DynamoDBLocal设置aws.access.key和aws.secret.key? - How to set aws.access.key and aws.secret.key for inMemory DynamoDBLocal in java? 如何在Elastic Beanstalk上为Amazon SES传递AWS_ACCESS_KEY_ID? - How do I pass AWS_ACCESS_KEY_ID for Amazon SES on Elastic Beanstalk? 如何在运行时通过 AWS 注入密钥 - How to inject a secret key at runtime via AWS 调用方法时如何修复错误? - how to fix an error when calling a method? 没有访问权限的AWS S3上载和Java中的密钥 - AWS S3 upload without access and secret key in Java 无法使用AWS SES API发送电子邮件。 错误消息,状态码:403 - Emails could not be sent using AWS SES APIs. Error message with Status Code: 403 AWS Java SDK 错误:请求签名“与提供的签名不匹配”检查您的密钥等。但凭证是正确的 - AWS Java SDK error: request signature 'not match signature provided' Check your key, etc. But credentials are correct 如何以及何时在AWS SES Java SDK中使用``异步&#39;&#39; - How and When To Use 'Async' in AWS SES Java SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM