繁体   English   中英

AWS SAM Lambda OpenSearch 策略

[英]AWS SAM Lambda policy for OpenSearch

我无法获得适用于 Lambda function 到 OpenSearch 的有效 IAM 策略。

  Replicate:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub ${AWS::StackName}-Replicate
      Description: !Sub
        - Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
        - ResourceName: DBReplicate
      CodeUri: ../src/Replicate
      Handler: index.handler
      Runtime: nodejs16.x
      MemorySize: 3008
      Timeout: 30
      Tracing: Active
      Policies:
        - PolicyName: Access
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - es:*
            Resource:
              - arn:aws:es:eu-west-1:22222222222:domain/mynewdomain
              - DomainName: mynewdomain
      Events:
        MyDynamoDBtable:
          Type: DynamoDB
          Properties:
            Stream: !Ref TableStreamArn
            StartingPosition: TRIM_HORIZON
            BatchSize: 1

运行sam validate ,我得到:

“策略”属性中索引 0 处的策略无效

所以最终得到了这个似乎有效的:

      OpenSearchAccess:
    Type: "AWS::IAM::Policy"
    Properties:
      PolicyName: "OpenSearchAccess"
      Roles:
        - !Ref MyIamRole
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Action:
              - 'es:*'
            Resource: arn:aws:es:eu-west-1:222222222:domain/domainname
  MyIamRole:
    Type: "AWS::IAM::Role"
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - "es.amazonaws.com"
            Action:
              - "sts:AssumeRole"
  Replicate:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Sub ${AWS::StackName}-DBReplicate
      Description: !Sub
        - Stack ${StackTagName} Environment ${EnvironmentTagName} Function ${ResourceName}
        - ResourceName: DBReplicate
      CodeUri: ../src/DBReplicate
      Handler: index.handler
      Runtime: nodejs16.x
      MemorySize: 3008
      Timeout: 30
      Tracing: Active
      Policies:
        - !Ref OpenSearchAccess

它是有效的,尽管在部署时收到有关某些无效 ARN 的错误

暂无
暂无

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

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