类型'this'的参数不能分配给AWS CDK中类型'Construct'的参数

时间:2020-09-04 17:08:51

标签: typescript aws-cdk

在使用CDK时,我遇到了一个问题,因为this属性出错,并说我无法将'this'分配给type结构的参数。这是从const s3ListLambdaRole部分开始发生的,并且在此之后进行的每个新变量声明也会因同一原因而出错。

import * as sns from '@aws-cdk/aws-sns';
import * as subs from '@aws-cdk/aws-sns-subscriptions';
import * as sqs from '@aws-cdk/aws-sqs';
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import * as lambda from '@aws-cdk/aws-lambda';
import * as path from 'path';
import { Bucket } from '@aws-cdk/aws-s3';
import * as iam from'@aws-cdk/aws-iam';


export class SecurityBaselineDevStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const testSecurityqueue = new sqs.Queue(this, 'testSecurityqueue', {
      visibilityTimeout: cdk.Duration.seconds(300)
    });

    const testSecuritytopic = new sns.Topic(this, 'testSecuritytopic');

      testSecuritytopic.addSubscription(new subs.SqsSubscription(testSecurityqueue));
    //Creating lambda role below
    const s3ListLambdaRole = new iam.Role(this, 's3ListLambdaRole', {
      assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
    });

    s3ListLambdaRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSLambdaFullAccess')) //creates LambdaFullAccess Role

    //Adding specific permissions to role now

    s3ListLambdaRole.addToPolicy(new iam.PolicyStatement({
      resources: ['*'], //adds full access to lamda
      actions: ['s3']
    }));

    const s3ListLambda = new lambda.Function (this, 's3ListLambda', {
      runtime: lambda.Runtime.PYTHON_3_6,
      handler: 'listS3.handler',
      role:s3ListLambdaRole,
      code: lambda.Code.fromAsset(path.join(__dirname, '../lambda'))
    });

    const testSecurityBucket = new s3.Bucket(this, 'testSecurityBucket');






    }

  }

提前谢谢!

2 个答案:

答案 0 :(得分:0)

更新您的CDK库。这通常是由您的CDK库具有不同版本引起的。 npm update -g aws-cdk

答案 1 :(得分:-1)

问题在于@ aws-cdk / lambda依赖项与@ aws-cdk / sqs和@ aws-cdk / sns依赖项版本不同。