List S3 lambda
This commit is contained in:
parent
d071dfaa4f
commit
72e2884786
@ -1,7 +1,7 @@
|
|||||||
group 'pl.grondek'
|
group 'pl.grondek'
|
||||||
version '1.0-SNAPSHOT'
|
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
version '1.0-SNAPSHOT'
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
13
s3-lambda/build.gradle
Normal file
13
s3-lambda/build.gradle
Normal file
@ -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
|
||||||
|
}
|
@ -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<Void, List<String>> {
|
||||||
|
@Override
|
||||||
|
public List<String> 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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
rootProject.name = 'aws'
|
rootProject.name = 'aws'
|
||||||
|
|
||||||
include "left-pad-lambda"
|
include "left-pad-lambda"
|
||||||
|
include "s3-lambda"
|
Loading…
Reference in New Issue
Block a user