Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Lookup S3 Bucket and add a trigger to invoke a lambda

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

From the git issue tracker https://github.com/aws/aws-cdk/issues/2004#issuecomment-479923251

Due to current limitations with CloudFormation and the way we implement bucket notifications in the CDK, it is impossible to add bucket notifications to an imported bucket. This is why the event source uses s3.Bucket instead of s3.IBucket.

You could use outPutObject:

 const bucket = s3.Bucket.import(this, 'B', { bucketName: 'my-bucket' }); const fn = new lambda.Function(this, 'F', { code: lambda.Code.inline('boom'), runtime: lambda.Runtime.NodeJS810, handler: 'index.handler' }); bucket.onPutObject('put-object', fn);

But reading further, this doesn't seem to work either.

It seems that the answer currently is:

It is impossible to configure.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!