Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda