【问题标题】:Set AWS Kinesis cloudformation template设置 AWS Kinesis cloudformation 模板
【发布时间】:2019-04-23 06:23:37
【问题描述】:

我是 AWS cloudformation 的新手,需要创建 Kinesis 数据流,然后使用 python 代码将记录写入此流。我能够通过 cloudformation 模板创建数据流,但无法设置权限。我将如何附加权限以允许某些用户组使用 python 库写入此 kinesis 数据流?

我当前的模板代码是,

AWSTemplateFormatVersion: '2010-09-09'
Description: 'This template will create an AWS Kinesis DataStream'

Parameters:

CFNStreamName:
    Description: This will be used to name the Kinesis DataStream
    Type: String
    Default: 'data-stream'

CFNRetensionHours:
    Description: This will be used to set the retension hours
    Type: Number
    Default: 168

CFNShardCount:
    Description: This will be used to set the shard count
    Type: Number
    Default: 2

Resources:
    MongoCDCStream:
Type: AWS::Kinesis::Stream
Properties:
  Name: !Ref CFNStreamName
  RetentionPeriodHours: !Ref CFNRetensionHours
  ShardCount: !Ref CFNShardCount
  StreamEncryption:
      EncryptionType: KMS
      KeyId: alias/aws/kinesis
Outputs:
    MongoCDCStream:
    Value: !Ref MongoCDCStream
    Export:
        Name: !Sub ${AWS::StackName}-MongoCDCStream

【问题讨论】:

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


    【解决方案1】:

    您需要传入(通过 cloudformation 参数)运行 Python 代码的 IAM 角色或用户。

    在模板中,创建附加到您传入的 IAM 角色/用户的 IAM 策略或 ManagedPolicy 并分配正确的权限。

    AWSTemplateFormatVersion: '2010-09-09'
    Description: 'This template will create an AWS Kinesis DataStream'
    
    Parameters:
    
    CFNStreamName:
        Description: This will be used to name the Kinesis DataStream
        Type: String
        Default: 'data-stream'
    
    CFNRetensionHours:
        Description: This will be used to set the retension hours
        Type: Number
        Default: 168
    
    CFNShardCount:
        Description: This will be used to set the shard count
        Type: Number
        Default: 2
    
    PythonCodeRole:
        Type: String
    # ^- Pass in role here.
    
    Resources:
        # Assign permission here.
        PythonCodePlicyAssignmen:
            Type: AWS::IAM::Policy
            Properties: 
                PolicyDocument: 
                    <assign needed permission here>
                    Version: "2012-10-17"
                    Statement:
                      - Effect: "Allow"
                        Action:
                          - "kinesis:*"
                        Resource: !Ref MongoCDCStream
                        # ^- here, use !Ref to tie in the correct resource id cleanly.
                PolicyName: python-code-permission
                Roles: [!Ref PythonCodeRole]
    
        MongoCDCStream:
            Type: AWS::Kinesis::Stream
            Properties:
                Name: !Ref CFNStreamName
                RetentionPeriodHours: !Ref CFNRetensionHours
                ShardCount: !Ref CFNShardCount
                StreamEncryption:
                  EncryptionType: KMS
                  KeyId: alias/aws/kinesis
    Outputs:
        MongoCDCStream:
        Value: !Ref MongoCDCStream
        Export:
            Name: !Sub ${AWS::StackName}-MongoCDCStream
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-10
      • 2017-10-30
      • 2017-01-28
      • 2017-04-16
      • 2021-07-20
      • 2016-12-12
      • 2018-05-04
      • 1970-01-01
      相关资源
      最近更新 更多