如何通过将自定义 SSL 证书用于 CloudFront 分配来排查问题?

2 分钟阅读
0

我拥有 AWS Certificate Manager (ACM) 或 AWS Identity and Access Management (IAM) 上的 SSL 证书,我希望将该证书用于我的 Amazon CloudFront 分配。我想排查我遇到的问题。

简短描述

以下是与在 CloudFront 分配上使用自定义 SSL 证书时最常见的问题:

  • 在设置分配时,您没有找到选择自定义 SSL 证书的选项。
  • 虽然您能将相同的证书用于您的负载均衡器,但却无法选择 SSL 证书。

解决方法

要排查与在 CloudFront 分配上使用自定义 SSL 证书时遇到的问题,请执行以下操作:

如果您使用的是从 ACM 请求的证书或导入到 ACM 的证书,则确认您的证书是否符合要求

如果您使用的是导入到 IAM 的证书,则验证 CloudFront 路径

将 SSL 证书导入 IAM 时,请提供正确的路径,以便 CloudFront 可以使用该证书。运行以下 AWS 命令行界面 (AWS CLI) 命令以使指定的 CloudFront 路径上传您的证书:

**注意:**在运行此命令之前,请确保将所有值替换为您的证书和 CloudFront 分配的详细信息。

aws iam upload-server-certificate --server-certificate-name CertificateName
--certificate-body file://public_key_certificate_file --private-key file://privatekey.pem 
--certificate-chain file://certificate_chain_file --path /cloudfront/DistributionName/

**注意:**如果在运行 AWS CLI 命令时收到错误, 请确保您使用的是最新的 AWS CLI 版本。 如果您未使用 CloudFront 路径上传证书,则运行以下命令以使用该路径更新您的证书:

aws iam update-server-certificate --server-certificate-name CertificateName 
--new-path /cloudfront/DistributionName/

注意:当您向 CloudFront 分配添加证书后,分配的状态将从已部署变为正在进行。将更改部署到所有 CloudFront 边缘站点时,分配的状态将重新变为已部署典型的部署时间是 5 分钟

在将证书从 ACM 或 IAM 分配给 CloudFront 分配时,请确认您拥有所需的权限

您用于分配证书的 IAM 用户或角色必须至少具有以下权限:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "acm:ListCertificates",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "cloudfront:ListDistributions",
                "cloudfront:ListStreamingDistributions"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "cloudfront:List*",
                "cloudfront:Get*",
                "cloudfront:Update*"
            ],
            "Resource": "arn:aws:cloudfront::account-id:distribution/distribution-id"
        },
        {
            "Effect": "Allow",
            "Action": "iam:ListServerCertificates",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:GetServerCertificate",
                "iam:UpdateServerCertificate"
            ],
            "Resource": "arn:aws:iam::account-id:server-certificate/certificate-name-with-path"
        }
    ]
}

相关信息

如何解决创建或更新 CloudFront 分配时的“InvalidViewerCertificate”错误?

在 CloudFront 中使用 SSL/TLS 证书的要求

相关视频

AWS 官方
AWS 官方已更新 1 年前