Skip to content

aws-lambda-event-sources: S3EventSource Requires Bucket, but only needs an IBucket #23940

@Styerp

Description

@Styerp

Describe the bug

I want to use an externally created bucket as an event notification source for a lambda

Expected Behavior

An IBucket can be used as the notification source

Current Behavior

Type errors. An IBucket cannot be assigned to a Bucket.

Reproduction Steps

import * as core from "aws-cdk-lib";
import * as event_sources from "aws-cdk-lib/aws-lambda-event-sources";
import * as s3 from "aws-cdk-lib/aws-s3";

const app = new core.App()
const ibucket = s3.Bucket.fromBucketName(app, "IBucket", "IBucket");
const eventSource = new event_sources.S3EventSource(ibucket, {events: [s3.EventType.OBJECT_CREATED]})

TS2345: Argument of type 'IBucket' is not assignable to parameter of type 'Bucket'.

Possible Solution

Since addEventNotification is the only method used by S3EventSource and is available on an IBucket, I think it should be safe to loosen the type restriction to IBucket.

Coercing the type and deploying works.

Additional Information/Context

No response

CDK CLI Version

2.40.0

Framework Version

No response

Node.js Version

16

OS

OSX

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions