import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaFunctionHandler implements RequestHandler<Request, Response> {
public Response handleRequest(Request request, Context context) {
String greetingString = String.format("Hello %s %s.",
request.firstName, request.lastName);
return new Response(greetingString);
}
}
public class Test{
private static final Log logger = LogFactory.getLog(InvokeLambda.class);
private static final String awsAccessKeyId = "XXXXX";
private static final String awsSecretAccessKey = "XXXXX";
private static final String regionName = "eu-west-1";
private static Region region;
private static AWSCredentials credentials;
private static AWSLambdaClient lambdaClient;
private static AmazonS3Client s3Client;
private static void init() {
credentials = new BasicAWSCredentials(awsAccessKeyId,
awsSecretAccessKey);
s3Client = (credentials == null) ? new AmazonS3Client()
: new AmazonS3Client(credentials);
region = Region.getRegion(Regions.fromName(regionName));
s3Client.setRegion(region);
lambdaClient = (credentials == null) ? new AWSLambdaClient()
: new AWSLambdaClient(credentials);
lambdaClient.setRegion(region);
// lambdaClient.configureRegion(Regions.US_WEST_2);
}
/**
* The entry point into the AWS lambda function.
*/
public static void main(String... args) {
init();
getExistingBucket();
}
private static Bucket getExistingBucket() {
List<Bucket> buckets = s3Client.listBuckets();
for (Bucket bucket : buckets) {
logger.error(bucket.getName());
}
return null;
}
}