简体   繁体   English

如何在 cloudformation 中创建托管策略,允许 lambda 访问 aws 环境中的所有 s3 容器

[英]How to create a managed policy in cloudformation that allows lambda access to all s3 containers in an aws environment

I'm trying to create a managed policy for a lambda that allows it access to all s3 buckets in my environment.我正在尝试为 lambda 创建一个托管策略,允许它访问我环境中的所有 s3 存储桶。 This lambda basically scans the contents of each bucket and keys any object with the prefix archive/ if it older than thirty days.这个 lambda 基本上扫描每个存储桶的内容,如果超过三十天,则使用前缀 archive/ 键入任何 object。 I'm trying to create the policy in cloudformation but I keep getting a error when packaging that an end of the stream or document separator is expected.我正在尝试在 cloudformation 中创建策略,但在打包 stream 或文档分隔符的结尾时不断收到错误消息。 I know this is a yaml error but not sure exactly how to correct it.我知道这是一个 yaml 错误,但不确定如何纠正它。


 LambdaArchiveAccessPolicy:
    Type: AWS::IAM::ManagedPolicy
    Properties:
      ManagedPolicyName: LambdaArchiveAccessPolicy
      Description: Policy for allowing lambda to access s3 containers
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          Effect: Allow
          Action: 's3:*'
          Resource: !Sub 'arn:aws:s3:::*'

I suspect how I am defining the resource is wrong.我怀疑我如何定义资源是错误的。 I'd appreciate any guidance or suggestions我将不胜感激任何指导或建议

As per the YAML specification here , spacing is important in YAML files, and more specifically:根据此处的 YAML 规范,间距在 YAML 文件中很重要,更具体地说:

All sibling nodes must use the exact same indentation level.所有兄弟节点必须使用完全相同的缩进级别。

In your YAML your first line is indented three spaces, but subsequent indentation is only 2 spaces.在您的 YAML 中,您的第一行缩进了三个空格,但随后的缩进只有 2 个空格。 Correct the spacing by one and you will resolve your issue.将间距纠正一,您将解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM