AWS CloudFormation の「One or more of your origins or origin groups do not exist」(1 つ以上のオリジンまたはオリジングループが存在しません) というエラーを解決するにはどうすればよいですか?

所要時間2分
0

Amazon CloudFront ディストリビューションを含む AWS CloudFormation スタックを作成または更新しようとすると、次のエラーが表示されます。 「One or more of your origins or origin groups do not exist.」(1 つ以上のオリジンまたはオリジングループが存在しません)

簡単な説明

このエラーは、CacheBehavior または DefaultCacheBehaviorTargetOriginId プロパティが CloudFront のオリジンまたはオリジングループ ID と一致しない場合に発生します。この ID は、オリジンまたはオリジングループを一意に識別するユーザー定義の文字列です。テンプレートでオリジングループを定義し、CloudFormation を通じてリソースを管理する必要があります。

ヒント: ベストプラクティスとして、CloudFormation の外部でスタックリソースを変更しないようにします。外部で変更すると、スタックのテンプレートとスタックリソースの現在の状態との間に不一致が生じる可能性があります。スタックを更新または削除すると、不一致によりエラーが発生する可能性があります。

解決方法

1.    TargetOriginId が、定義されたオリジンまたはオリジングループのいずれかの ID と一致することを確認します。DefaultCacheBehavior または CacheBehavior のパラメータとして正しいオリジン ID を入力します。

次の JSON および YAML テンプレートスニペットの例では、DefaultCacheBehavior は単一のオリジンで CloudFront ディストリビューションを定義および使用します。また、オリジンは認証のためにオリジンアクセスアイデンティティ (OAI) を使用します。例では、オリジン ID は my-s3-origin に設定されています。

JSON:

{
  "AWSTemplateFormatVersion": "2010-09-09T00:00:00.000Z",
  "Resources": {
    "cloudfrontdistribution": {
      "Type": "AWS::CloudFront::Distribution",
      "Properties": {
        "DistributionConfig": {
          "DefaultCacheBehavior": {
            "ViewerProtocolPolicy": "https-only",
            "DefaultTTL": 3600,
            "ForwardedValues": {
              "Cookies": {
                "Forward": "none"
              },
              "QueryString": true
            },
            "TargetOriginId": "my-s3-origin"
          },
          "Enabled": true,
          "Origins": [
            {
              "DomainName": "my-s3-bucket.s3.amazonaws.com",
              "Id": "my-s3-origin",
              "S3OriginConfig": {
                "OriginAccessIdentity": {
                  "Fn::Sub": "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
                }
              },
              "OriginPath": "/my-content"
            }
          ]
        }
      }
    },
    "CloudFrontOriginAccessIdentity": {
      "Type": "AWS::CloudFront::CloudFrontOriginAccessIdentity",
      "Properties": {
        "CloudFrontOriginAccessIdentityConfig": {
          "Comment": {
            "Ref": "AWS::StackName"
          }
        }
      }
    }
  }
}

注: my-s3-origin をオリジン ID に、my-s3-bucket.s3.amazonaws.com をドメイン名に、/my-content をオリジンパスに置き換えます。

YAML:

AWSTemplateFormatVersion: 2010-09-09
Resources:
  cloudfrontdistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        DefaultCacheBehavior:
          ViewerProtocolPolicy: https-only
          DefaultTTL: 3600
          ForwardedValues:
            Cookies:
              Forward: none
            QueryString: true
          TargetOriginId: my-s3-origin
        Enabled: true
        Origins:
          - DomainName: 'my-s3-bucket.s3.amazonaws.com'
            Id: my-s3-origin
            S3OriginConfig:
              OriginAccessIdentity: !Sub origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}
            OriginPath: /my-content
          
  CloudFrontOriginAccessIdentity:
    Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
    Properties:
      CloudFrontOriginAccessIdentityConfig:
        Comment: !Sub ${AWS::StackName}

2.    CloudFront ディストリビューションをテストして、CloudFormation スタックが作成または更新されたことを確認します。


関連情報

CloudFront ディストリビューションでのさまざまなオリジンの使用

AWS CloudFormation コンソールでのスタックの作成

AWS CloudFormation ベストプラクティス

AWS公式
AWS公式更新しました 2年前
コメントはありません

関連するコンテンツ