【问题标题】:AWS Cloudformation download file from private S3 AWS4-HMAC-SHA256AWS Cloudformation 从私有 S3 AWS4-HMAC-SHA256 下载文件
【发布时间】:2018-02-04 02:41:03
【问题描述】:

我正在尝试在 cloudformation 构建期间使用此模板从 S3 存储桶下载文件。

它失败并显示以下错误消息。

不支持您提供的授权机制。请 使用 AWS4-HMAC-SHA256。

使用这个模板

https://raw.githubusercontent.com/awslabs/aws-hangouts/master/20140130_cfn/s3-role-authentication.json

 2017-08-26 03:13:38,763 [ERROR] Unhandled exception during build: Failed to retrieve https://hello.s3.amazonaws.com/index.html: HTTP Error 400 : <?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidRequest</Code><Message>The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.</Message><RequestId>5328A90F4EBF081D</RequestId><HostId>nUyURkNRX7Ty5xU1LiY3wO/aFDzjiWYw9JWq0PlVdmjMCqUP7sG8FN1w5BwmtEWc8IKpeMqkv6k=</HostId></Error>
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 171, in <module>
    worklog.build(metadata, configSets)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 129, in build
    Contractor(metadata).build(configSets, self)

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudformation


    【解决方案1】:

    【讨论】:

    • 这根本没有帮助。来自 OP 的错误消息正在发生,因为某些区域(例如 eu-central-1)中的存储桶仅支持使用“AWS4-HMAC-SHA256”机制进行身份验证。不幸的是,我没有找到任何解决方案来在 cloudformation 中设置它。
    【解决方案2】:

    我也收到“AWS4-HMAC-SHA256”错误,我将解释这个场景以及我是如何解决这个问题的,所以它会对某人有所帮助。出现错误是因为我的存储桶与我配置 cloudformation 堆栈的区域不同。

    • 使用https://&lt;bucket-region&gt;amazonaws.com/&lt;bucket&gt;/&lt;file-name&gt;作为bucket对象的url
    • 您需要在身份验证部分使用 相同的角色,该角色已在 EC2 实例的实例配置文件中使用。

    这是 cloudformation 模板

    Resources:
      MyEC2:
        Type: "AWS::EC2::Instance"
        Properties:
          IamInstanceProfile: !Ref IAMRoleS3FullAccessInstanceProfile 
        ......
        Metadata:
          AWS::CloudFormation::Authentication:
            S3BucketAccessCredential:
              type: "S3"
              roleName: !Ref IAMRoleS3FullAccess
    
          AWS::CloudFormation::Init:
            config:
              .....
              files:
                /etc/nginx/sites-available/webserver:
                  source: "https://<bucket-region>amazonaws.com/<bucket>/<file-name>"
                  mode: "000600"
                  owner: root
                  group: root
                  authentication: "S3BucketAccessCredential"
    
      # S3 Access role
      IAMRoleS3FullAccess:
        Type: AWS::IAM::Role
        Properties:
          ManagedPolicyArns: 
            - "arn:aws:iam::aws:policy/AmazonS3FullAccess"
          AssumeRolePolicyDocument:
            Version: '2012-10-17'
            Statement:
            - Effect: Allow
              Principal:
                Service:
                - ec2.amazonaws.com
              Action:
              - sts:AssumeRole
          Path: "/"
    
      # Instance profile
      IAMRoleS3FullAccessInstanceProfile:
        Type: AWS::IAM::InstanceProfile
        Properties:
          Path: "/"
          Roles:
          - !Ref IAMRoleS3FullAccess  
    

    【讨论】:

      猜你喜欢
      • 2015-01-09
      • 1970-01-01
      • 2015-04-15
      • 1970-01-01
      • 2023-01-25
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多