成员必须满足正则表达式模式:.*

问题描述 投票:0回答:1

我正在从 AWS CLI 创建一个新的 ElasticSearch/OpenSearch 域,并使用 shell 变量中定义的访问策略和开放访问策略,但失败了。

ACCESS_POLICY_JSON=$(cat <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowElasticsearchAccess",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:${AWS_REGION}:${AWS_ACCOUNT}:domain/es-dev-tenant/*"
    }
  ]
}
EOF
)

aws opensearch create-domain --domain-name es-dev-tenant \
    --engine-version ${ES_VERSION} --region ${AWS_REGION} \
    --cluster-config InstanceType=${ES_INSTANCE_SIZE},InstanceCount=${ES_INSTANCE_COUNT},DedicatedMasterEnabled=false,ZoneAwarenessEnabled=false,MultiAZWithStandbyEnabled=false \
    --vpc-options $ES_VPC_OPTIONS --ebs-options EBSEnabled=true,VolumeType=gp2,VolumeSize=${ES_VOLUME_SIZE} \
    --access-policies "$ACCESS_POLICY_JSON"

错误是:

An error occurred (ValidationException) when calling the CreateDomain operation: 1 validation error detected: Value '{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Allow elasticsearch access.",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:ap-southeast-2:6xxxx:domain/es-dev-tenant/*"
    }
  ]
}' at 'accessPolicies' failed to satisfy constraint: Member must satisfy regular expression pattern: .*
elasticsearch aws-cli opensearch
1个回答
0
投票

使用

| jq -c .

将多行 JSON 转换为单行
ACCESS_POLICY_JSON=$(cat <<EOF | jq -c .
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowElasticsearchAccess",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "arn:aws:es:${AWS_REGION}:${AWS_ACCOUNT}:domain/es-dev-tenant/*"
    }
  ]
}
EOF
)
© www.soinside.com 2019 - 2024. All rights reserved.