diff --git a/build.gradle b/build.gradle index 2e3d64a..c1a3455 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ group 'pl.grondek' -version '1.0-SNAPSHOT' subprojects { + version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 diff --git a/s3-lambda/build.gradle b/s3-lambda/build.gradle new file mode 100644 index 0000000..5455bde --- /dev/null +++ b/s3-lambda/build.gradle @@ -0,0 +1,13 @@ +dependencies { + compile 'com.amazonaws:aws-lambda-java-core:1.2.0' + compile 'com.amazonaws:aws-java-sdk-s3:1.11.283' +} + +task fatJar(type: Jar) { + manifest { + attributes 'Implementation-Title': 'Gradle Jar File Example', + 'Implementation-Version': version + } + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} \ No newline at end of file diff --git a/s3-lambda/src/main/java/pl/grondek/aws/lambda/s3/ListS3Lambda.java b/s3-lambda/src/main/java/pl/grondek/aws/lambda/s3/ListS3Lambda.java new file mode 100644 index 0000000..4179372 --- /dev/null +++ b/s3-lambda/src/main/java/pl/grondek/aws/lambda/s3/ListS3Lambda.java @@ -0,0 +1,26 @@ +package pl.grondek.aws.lambda.s3; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.S3ObjectSummary; + +import java.util.List; +import java.util.stream.Collectors; + +public class ListS3Lambda implements RequestHandler> { + @Override + public List handleRequest(Void input, Context context) { + final String bucketName = System.getenv("BUCKET_NAME"); + final String bucketRegion = System.getenv("REGION"); + + return AmazonS3ClientBuilder.standard() + .withRegion(bucketRegion) + .build() + .listObjects(bucketName) + .getObjectSummaries() + .stream() + .map(S3ObjectSummary::getKey) + .collect(Collectors.toList()); + } +} diff --git a/settings.gradle b/settings.gradle index 31211bb..5208dc5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ rootProject.name = 'aws' -include "left-pad-lambda" \ No newline at end of file +include "left-pad-lambda" +include "s3-lambda" \ No newline at end of file