public class CreateS3Bucket {
public static void main(String[] args) throws IOException {
BasicAWSCredentials creds = new BasicAWSCredentials("aws-access-key", "aws-secret-key");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).build();
Region region = Region.getRegion(Regions.US_EAST_1);
s3Client.setRegion(region);
try {
String bucketName = "testBucket" + UUID.randomUUID();
s3Client.createBucket(bucketName);
System.out.println("Bucket Created Successfully.");
} catch(AmazonServiceException awse) {
System.out.println("This means that your request made it AWS S3 but got rejected");
System.out.println("Error Message:" +awse.getMessage());
System.out.println("Error Message:" +awse.getErrorCode());
System.out.println("Error Message:" +awse.getErrorType());
System.out.println("Error Message:" +awse.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("The Amazon Client encountered an Error with network Connectivity");
System.out.println("Error Message:" + ace.getMessage());
}
}
}
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class LambdaFunctionHandler implements RequestHandler<String, String> {
@Override
public String handleRequest(String input, Context context) {
context.getLogger().log("Input: " + input);
return null;
}
}