I am having an issue while using the CDK in that the this
property is erroring and saying that I can't assign 'this' to parameter of type construct. This is happens start on the const s3ListLambdaRole
part and makes every new variable declaration after that also error for the same thing.
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');
}
}
Thank you in advance!