CDK无法创建CloudWatch Logs SubscriptionFilter

时间:2019-09-02 13:31:25

标签: python aws-cdk

我尝试用CDK框架创建Cloud Watch Logs订阅筛选器,但没有成功。

from aws_cdk import (
    aws_kinesis,
    aws_iam,
    aws_logs,
    core
)


class LambdaStack(core.Stack):
    def __init__(self, app: core.App, id: str, **kwargs) -> None:
        super().__init__(app, id, **kwargs)

        stream = aws_kinesis.Stream(
            self,
            "datalake-stream",
            stream_name="datalake-stream"
        )

        role = aws_iam.Role(
            self,
            "datalake-role",
            role_name="datalake-role",
            assumed_by=aws_iam.ServicePrincipal('logs.eu-west-1.amazonaws.com')
        )

        role.add_to_policy(aws_iam.PolicyStatement(
            actions=['kinesis:PutRecord'],
            resources=[stream.stream_arn],
        ))

        role.add_to_policy(aws_iam.PolicyStatement(
            actions=['iam:PassRole'],
            resources=[role.role_arn],
        ))

        log_group = aws_logs.LogGroup(
            self,
            "datalake-logroup",
            log_group_name="/test")

        aws_logs.SubscriptionFilter(
            self,
            "-datalake-subscriptionfilter",
            log_group=log_group,
            filter_pattern=aws_logs.FilterPattern().all_events,
            destination=stream
        )


app = core.App()
LambdaStack(app, "cwllogstos3", env={'region': 'eu-west-1'})
app.synth()

我遇到了这些错误:

$ cdk部署

  

回溯(最近一次通话最后一次):文件“ infra.py”,第52行,在          LambdaStack(app,“ cwllogstos3”,env = {'region':'eu-west-1'})文件   “ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_runtime.py”,   第66行,致电       inst = super()。调用(* args,** kwargs)文件“ infra.py”,第47行,位于 init 中       destination = stream文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_runtime.py”,   第66行,致电       inst = super()。调用(* args,** kwargs)文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/aws_cdk /aws_logs/init.py”,   第2060行,在 init 中       jsii.create(SubscriptionFilter,self,[scope,id,props])文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/ init .py”,   第207行,在创建中       args = _make_reference_for_native(self,args),文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/init.py ”,   _make_reference_for_native中的第119行       在[d中为i返回[_make_reference_for_native(内核,i)]文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/init .py”,   第119行,在       在[d中为i返回[_make_reference_for_native(内核,i)]文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/init .py”,   _make_reference_for_native中的第124行       返回_make_reference_for_native(内核,struct_data)文件“ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/init.py”,   _make_reference_for_native中的第117行       在d.items()中为k,v返回{k:_make_reference_for_native(kernel,v)}   “ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/init.py”,   117行,在       在d.items()中为k,v返回{k:_make_reference_for_native(kernel,v)}   “ /Users/enrico.pesce/Documents/GitHub/cwllogstos3/venv/lib/python3.7/site-packages/jsii/_kernel/init.py”,   第130行,在_make_reference_for_native中       d。 jsii__type =“对象” AttributeError:'方法'对象没有属性' jsii__type '子进程退出,错误1

1 个答案:

答案 0 :(得分:0)

我认为问题出在这一行:

filter_pattern=aws_logs.FilterPattern().all_events

您正在传递对方法all_events的引用。但是您应该传递IFilterPattern接口的实例。

尝试将其更改为:

filter_pattern=aws_logs.FilterPattern().all_events()