s3 event is not triggering AWS Lambda function while uploading jar file from bamboo build plan.

+1 vote

s3 event is not triggering AWS Lambda function while uploading jar file from bamboo build plan. 

And if I upload Jar manually in s3 Bucket then S3Event is triggering AWS Lambda function correctly. Below are the permission Bucket.

Below is my LambdaFuncton code:

package com.lambda;


import com.amazonaws.services.lambda.AWSLambda;

import com.amazonaws.services.lambda.AWSLambdaClientBuilder;

import com.amazonaws.services.lambda.model.UpdateFunctionCodeRequest;

import com.amazonaws.services.lambda.model.UpdateFunctionCodeResult;

import com.amazonaws.services.lambda.runtime.Context;

import com.amazonaws.services.lambda.runtime.RequestHandler;

import com.amazonaws.services.lambda.runtime.events.S3Event;

import com.amazonaws.services.s3.AmazonS3;

import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import com.amazonaws.services.s3.model.GetObjectRequest;

import com.amazonaws.services.s3.model.S3Object;

import org.apache.commons.io.IOUtils;


import java.io.IOException;

import java.nio.ByteBuffer;


public class TestLambdaS3Event implements RequestHandler<S3Event, String> {


private AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();

AWSLambda s3EventClient = AWSLambdaClientBuilder.standard().build();


public TestLambdaS3Event() {

}



@Override

public String handleRequest(S3Event event, Context context) {

context.getLogger().log("Received event: " + event);


// Get the object from the event and show its content type

String bucket = event.getRecords().get(0).getS3().getBucket().getName();

String key = event.getRecords().get(0).getS3().getObject().getKey();

try {

S3Object response = s3.getObject(new GetObjectRequest(bucket, key));

String contentType = response.getObjectMetadata().getContentType();


byte[] byteArray = IOUtils.toByteArray(response.getObjectContent());

UpdateFunctionCodeRequest request = new UpdateFunctionCodeRequest().withFunctionName("my_function")

.withZipFile(ByteBuffer.wrap(byteArray));

System.out.println("request## " + request);

UpdateFunctionCodeResult responseUpdate = s3EventClient.updateFunctionCode(request);

System.out.println("responseUpdate## "+responseUpdate);

return contentType;

} catch (IOException e) {

e.printStackTrace();

context.getLogger().log(String.format("Error getting object %s from bucket %s. Make sure they exist and"

+ " your bucket is in the same region as this function.", bucket, key));

return e.toString();

}


}


}
Apr 3 in Others by Abhishek
• 280 points
108 views
Can you share your error?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer

how to install Amazon AWS Command Line Interface tools on Bamboo build agent.

Hi@Abhishek, You need to set the following parameters ...READ MORE

answered Apr 6 in Others by MD
• 23,050 points
66 views
0 votes
1 answer

How to check if array is multidimensional or not?

Since the 'second dimension' could be just ...READ MORE

answered Nov 5, 2018 in Others by DataKing99
• 8,150 points
1,012 views
0 votes
1 answer

How is regression testing different from functional testing?

Functional testing is testing a section of code ...READ MORE

answered Feb 18, 2019 in Others by Mythlli
39 views
0 votes
1 answer

How is functional testing different from non functional testing?

Hey @Sinha, functional testing is performed using the ...READ MORE

answered Feb 18, 2019 in Others by Anusha
47 views
0 votes
2 answers

What is white box testing and how is it different from black box testing?

Black Box Testing is a software testing method in ...READ MORE

answered Feb 20, 2019 in Others by preetiagarwal
• 170 points
171 views
0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 6, 2019 in Others by Frankie
• 9,810 points
76 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,420 points
495 views
0 votes
1 answer