AWS CloudFront将新域添加到分发中并设置新证书

时间:2019-09-30 07:06:30

标签: amazon-cloudfront

因此,我试图自动将新域添加到现有CF分发中,并且收到一条Rate exceeded错误消息。

我正在使用aws/aws-sdk-php,但是当我使用aws-cli尝试相同的命令时遇到相同的错误。

这是我到目前为止的代码:

private function addDistributionAliasAndSetNewCertificate(string $distributionId, string $domainName, string $certificateARN): void
{
    $result = $this->cloudFront->getDistributionConfig(['Id' => $distributionId]);

    $eTag = $result['ETag'];
    $distributionConfig = $result['DistributionConfig'];

    // if the domain is already in the distribution return early.
    if (in_array($domainName, $distributionConfig['Aliases']['Items'], true)) {
        StdOut::writeLine("Domain `{$domainName}` already found in distribution `{$distributionId}` config.");
        return;
    }

    $distributionConfig['Aliases']['Items'][] = $domainName;
    $distributionConfig['Aliases']['Quantity'] = count($distributionConfig['Aliases']['Items']);

    $distributionConfig['ViewerCertificate'] = [
        'ACMCertificateArn' => $certificateARN,
        'MinimumProtocolVersion' => 'TLSv1.1_2016',
    ];
    $distributionConfig['Comment'] = 'Updated by `' . getenv('HOST') . '` on `' . date(DATE_ATOM) . '`';

    try {
        $this->cloudFront->updateDistribution([
            'Id' => $distributionId,
            'DistributionConfig' => $distributionConfig,
            'IfMatch' => $eTag,
        ]);
    } catch (CloudFrontException $e) {
        StdOut::writeLine($e->getAwsErrorMessage());
    }
}

这进入catch块,并显示错误消息Rate exceeded

当我使用cli工具执行相同操作时,得到以下输出: An error occurred (Throttling) when calling the UpdateDistribution operation (reached max retries: 4): Rate exceeded

我在两次通话之间已经等待了几天,所以差异为0。 我在做错什么吗?

1 个答案:

答案 0 :(得分:0)

我知道了。

问题是我覆盖/移除了ViewerCertificate.SSLSupportMethod键。