Created
April 12, 2018 04:30
-
-
Save DylanCh/d71824f24bb93cdb061e05515dd79aa2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
import com.amazonaws.auth.BasicAWSCredentials; | |
import com.amazonaws.services.lambda.runtime.Context; | |
import com.amazonaws.services.lambda.runtime.RequestStreamHandler; | |
import com.amazonaws.services.s3.AmazonS3; | |
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |
import com.amazonaws.services.s3.model.ObjectMetadata; | |
import com.amazonaws.services.s3.model.PutObjectRequest; | |
import com.amazonaws.services.s3.model.PutObjectResult; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
public class S3Upload implements RequestStreamHandler{ | |
private final String ACCESS_KEY = ""; | |
private final String SECRET_KEY = ""; | |
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) { | |
//https://stackoverflow.com/a/41952575/5531761 | |
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials( | |
new AWSStaticCredentialsProvider( | |
new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY))).build(); | |
PutObjectResult putObjectResult= s3Client.putObject(new PutObjectRequest("codesupdates","file.txt",inputStream, new ObjectMetadata())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment