I'm using the new AWS CDK(Cloud Development Toolkit) to build the infrastructure on AWS in Java.
What I have to do: lookup an s3 bucket and add a trigger that invokes a lambda function.
What I have done:
Looked up s3 bucket:
IBucket bucket = Bucket.fromBucketName(scope, bucketId, bucketName);Add a new event source to the existing lambda:
IEventSource eventSource = getObjectCreationEvent(); lambda.addEventSource(eventSource);Where
getObjectCreationEvent()is:private S3EventSource getObjectCreationEvent() { return new S3EventSource(bucket, new S3EventSourceProps() { @Override public List<EventType> getEvents() { return Collections.singletonList(EventType.OBJECT_CREATED); } }); }
What is the problem:
The type of bucket parameter in the S3EventSource constructor is Bucket but every lookup method (e.g. the Bucket.fromBucketName()) returns an IBucket and not a Bucket, so there is a signature mismatch. If I cast IBucket to Bucket I have a ClassCastException.