当前位置: 首页 > 知识库问答 >
问题:

为什么AWS RDS显示异常-状态代码:400;错误代码:InvalidParameterValue

欧阳俊晖
2023-03-14

代码-

private static String getDBInstanceTag(AmazonRDS amazonRDS, String dbInstanceIdentifier, String region, String tagKey) {

        log.info("Trying to fetch dbInstanceIdentifier - " + dbInstanceIdentifier + " in db instance region - " + region);
        String arn = String.format("arn:aws:rds:" + region + ":%s:db:%s",
                SyncJobConstants.AWSProperties.AWS_ACCOUNT_NUMBER,
                dbInstanceIdentifier);
        ListTagsForResourceResult tagsList = amazonRDS.listTagsForResource(
                new ListTagsForResourceRequest().withResourceName(arn));

        for(Tag tag : tagsList.getTagList()) {
            if(tagKey.equalsIgnoreCase(tag.getKey())) {
                return tag.getValue();
            }
        }

        throw new InternalProcessingException(tagKey + " is not present in given dbInstance - " + tagsList);
    }

    public static String getDBInstanceTag(String dbInstanceIdentifier, String tagKey) throws IOException {

        AWSCredentials credentials = new PropertiesCredentials(
                RedshiftUtil.class.getClassLoader().getResourceAsStream("AWSCredentials.properties"));
        AmazonRDS amazonRDS = new AmazonRDSClient(credentials);

        DBInstance dbInstance = new DBInstance();
        dbInstance.setDBInstanceIdentifier(dbInstanceIdentifier);

        for(String region : SyncJobConstants.AWSProperties.RDS_REGIONS) {
            try {
                return getDBInstanceTag(amazonRDS, dbInstanceIdentifier, region, tagKey);
            } catch (DBInstanceNotFoundException e) {
                log.info("dbInstanceIdentifier - " + dbInstanceIdentifier + " is not present in db instance region - " + region);
            } catch (AmazonServiceException e) {
                if ( "AccessDenied".equals(e.getErrorCode()) ) {
                    log.info("dbInstanceIdentifier - " + dbInstanceIdentifier + " is not present in db instance region - " + region);
                } else {
                    throw new InternalProcessingException("Not able to fetch dbInstance details from RDS. DBInstanceId - " + dbInstanceIdentifier, e);
                }
            }
        }

        throw new InvalidRequestException("RDS endpoint details is not correct.");
    }

即使db实例存在,它也会为某些调用抛出错误。错误详细信息-

Caused by: com.amazonaws.AmazonServiceException: The specified resource name does not match an RDS resource in this region. (Service: AmazonRDS; Status Code: 400; Error Code: InvalidParameterValue; Request ID: b0e01d56-36ca-11e6-8441-1968d9061f57)
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1182)
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:770)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:489)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:310)
    at com.amazonaws.services.rds.AmazonRDSClient.invoke(AmazonRDSClient.java:5197)
    at com.amazonaws.services.rds.AmazonRDSClient.listTagsForResource(AmazonRDSClient.java:1997)

你能告诉我我在这里缺了什么吗?

错误含义-

public static final List RDS_REGIONS = Arrays.asList("us-east-1",
                "us-west-1",
                "us-west-2",
                "eu-west-1",
                "eu-central-1",
                "ap-northeast-1",
                "ap-northeast-2",
                "ap-southeast-1",
                "ap-southeast-2",
                "sa-east-1");

共有1个答案

田意致
2023-03-14

这似乎是一个与区域相关的问题-您的RDS实例是否位于区域US-East-1中?(那是Amazon SDK的默认区域)

登录Amazon web console并确认该地区。请设置正确的区域,然后重试。

参考:AWS区域选择

 类似资料:
  • 错误:无法找到或加载主类MyGridLayout.MyGridLayout C:\users\home\AppData\local\netbeans\cache\8.2\executor-snippets\run.xml:53:Java返回:1构建失败(总时间:0秒)

  • 我喜欢通过基于Java的AWS-CDK版本0.24.1创建cognito用户池。在我收到了InvalidParameterException错误。 服务:AWSCognitoIdentityProvider 状态代码:400 错误代码:ValueDealPosialExtExc:Qualito无效属性DATABATYPE输入,考虑使用提供的属性数据类型枚举 可能使用自动验证属性(Arrays.as

  • 我得到一个AWS错误代码:SignatureDoesNotMatch,状态代码:403时,试图通过亚马逊SES发送邮件。 我已经确认我正在使用通过https://console.aws.amazon.com/iam/home?#users创建的正确凭据,错误仍然存在。 我假设我在iam/home上创建的凭据实际上是全局的,但我不知道我进一步做错了什么。整个错误是: AWS错误代码:Signatur

  • 注释了println语句,但未注释unicode。为什么?

  • 问题内容: 我被告知不要像这样添加内容: 这有什么问题?我还有什么其他选择? 问题答案: 每次设置时,都必须解析HTML,构造DOM并将其插入文档中。这需要时间。 例如,如果有数千个div,表,列表,图像等,则调用将导致解析器重新重新解析 所有这些内容 。这也可能破坏对已经构造的DOM元素的引用,并引起其他混乱。实际上,您要做的就是在末尾附加一个新元素。 最好只致电: 这样,将不会再次解析的现有内

  • 我正在尝试使用以下代码使用 Groovy 执行 get 请求: String url = “url of endpoint” def responseXml = new XmlSlurper().parse(url) 如果endpoint返回的状态为200,则一切正常,但有一种情况,我们必须验证如下所示的错误响应,返回的状态为400: 在这种情况下,parse方法抛出: