【问题标题】:Cloudformation template is unable to execute retrieval of mount targetCloudformation 模板无法执行挂载目标的检索
【发布时间】:2019-03-11 08:31:17
【问题描述】:

我的 cloudformation 模板的用户数据中有以下命令:

MOUNT_TARGET_IP=$(aws efs describe-mount-targets --file-system-id fs-xxxxxxx --query 'MountTargets[*].IpAddress' --output text)

在我的模板中,我还有以下政策:

MyPolicy:
Type: "AWS::IAM::Policy"
Properties:
  PolicyName: !Sub "${AWS::StackName}_bucket_and_mount_targets_policy"
  PolicyDocument: 
    Version: "2012-10-17"
    Statement: 
      -
        Effect: "Allow"
        Action: "s3:GetObject"
        Resource: !Sub "arn:aws:s3:::${AuthorizedKeyBucketName}/authorized_keys"
      -
        Effect: "Allow"
        Action: "s3:ListBucket"
        Resource: !Sub "arn:aws:s3:::${AuthorizedKeyBucketName}"
      -
        Effect: "Allow"
        Action: "elasticfilesystem:DescribeMountTargets"
        Resource: "arn:aws:elasticfilesystem:us-east-1:xxxxxxxxxx:file-system/fs-xxxxxxx"
  Roles: 
    - 
      !Ref MyRole

我不确定为什么我仍然收到以下错误:

You must specify a region. You can also configure your region by running "aws configure".

当我ssh进入实例,然后手动配置区域和访问密钥,然后尝试执行上述语句,似乎工作正常。

有什么想法吗?

【问题讨论】:

  • 您使用的是amazon linux AMI,还是其他的?

标签: amazon-web-services amazon-cloudformation amazon-iam amazon-efs


【解决方案1】:

大多数 AWS CLI 命令都需要配置一个区域,而您尚未在此处配置一个。

您可以更改 CLI 命令以指定区域:

MOUNT_TARGET_IP=$(aws efs describe-mount-targets \
  --file-system-id fs-xxxxxxx \
  --query 'MountTargets[*].IpAddress' \
  --region ... \  # add this
  --output text)

或者您可以设置 AWS_DEFAULT_REGION 变量:

AWS_DEFAULT_REGION=...
export AWS_DEFAULT_REGION
MOUNT_TARGET_IP=$(aws efs describe-mount-targets --file-system-id fs-xxxxxxx \
  --query 'MountTargets[*].IpAddress' --output text)

或者您可以让您的脚本运行 aws configure 或以其他方式在 ~/.aws/config 中提供该区域。

请注意,不建议使用访问密钥配置 AWS CLI。您应该改用 IAM 角色。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-08
    • 2020-09-24
    • 1970-01-01
    • 2017-07-02
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    相关资源
    最近更新 更多