Upload a folder to an S3 bucket using java aws sdk - amazon-web-services

I'm trying to upload an entire folder to AWS S3 bucket. I'm successful at uploading individual files, but couldn't find a way to upload the entire folder.
AWS CLI has an option called sync, does and equivalent methods available in Java SDK?
Sample code for uploading individual objects is as below (only part)
final PutObjectRequest dashboardUploadRequest = PutObjectRequest.builder()
.bucket(aws.getApplihealthReportBucket())
.key(projectName + "/"+ executionConfig.getTestType() +"/" + aws.getS3Folder() + "/index.html").build();
S3Client s3 = S3Client.builder().credentialsProvider(credentialsProvider).build()
s3.putObject(dashboardUploadRequest, Paths.get(resultsDirectory + "/extent.html"));

There are no way to upload folder directly to s3. Only forearch and upload file by file.
Or using CLI
https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html

The TransferManager API in Java SDK provides methods to upload a directory to S3.

Related

Clean way to sync public s3 bucket to my private s3 bucket

Binance made its data public through an s3 endpoint. The website is 'https://data.binance.vision/?prefix=data/'. Their bucket URL is 'https://s3-ap-northeast-1.amazonaws.com/data.binance.vision'. I want to download all the files in their bucket to my own s3 bucket. I can:
crawl this website and download the CSV files.
make a URL builder that builds all the URLs and downloads the CSV files using those URLs.
Since their data is stored on s3. I wonder if there is a cleaner way to sync their bucket to my bucket.
Is the third way really doable?
If you want to copy it to your own s3 bucket, you can do:
aws s3 sync s3://data.binance.vision s3://your-bucket-name --no-sign-request
If you want to copy it to your own computer into your current folder (.) you can do:
aws s3 sync s3://data.binance.vision . --no-sign-request

how to download file from public s3 bucket using console

I want to download the file from a public S3 bucket using AWS console. When I put the below in the browser but getting an error. Wanted to visually see what else is there in that folder and explore
Public S3 bucket :
s3://us-east-1.elasticmapreduce.samples/flightdata/input
It appears that you are wanting to access an Amazon S3 bucket that belongs to a different AWS account. This cannot be done via the Amazon S3 management console.
Instead, I recommend using the AWS Command-Line Interface (CLI). You can use:
aws s3 ls s3://flightdata/input/
That will show you the objects stored in that bucket/path.
You could then download the objects with:
aws s3 sync s3://flightdata/input/ input

Deploy Lambda function to S3 bucket subdirectory

I am trying to deploy a Lambda function to AWS from S3.
My organization currently does not provide the ability for me to upload files to the root of an S3 bucket, but only to a folder (ie: s3://application-code-bucket/Application1/).
Is there any way to deploy the Lambda function code through S3, from a directory other than the bucket root? I checked the documentation for Lambda's CreateFunction AWS command and could not find anything obvious.
You need to zip your lambda package and upload to S3 in any folder.
You can then provide an https S3 url of the file to upload to lambda
function.
The S3 bucket needs to be in the same region as that of the lambda
function.
Make sure you zip from the folder, i.e when the package is unzipped,
the files should be extracted in the same directory as the unzip
command, and should not create a new directory for the contents.
I have this old script of mine that I used to automate lambda deployments.
It needs to be refactored a bit, but still usable.
It gets as input the lambda name and the zip file path located locally on your PC.
It uploads it to S3 and publishes to the AWS Lambda.
You need to set AWS credentials with IAM roles that allows:
S3 upload permission
AWS Lambda update permission
You need to modify the bucket name and the path you want your zip to be uploaded to. (lines 36-37).
That's it.

Send download link to Amazon Bucket folder

I need to send someone a link to download a folder stored in an amazon S3 bucket. Is this possible?
You can do that using the AWS CLI
aws s3 sync s3://<bucket>/path/to/folder/ .
There are many options if you need to filter specific files etc ... check the doc page
You can also use Minio Client aka mc for this. It is open source and S3 compatible. mc policy command should do this for you.
Set bucket to "download" on Amazon S3 cloud storage.
$ mc policy download s3/your_bucket
This will add downloadable policy on all the objects inside bucket name your_bucket and an object with name yourobject
can be accessed with URL below.
https://your_bucket.s3.amazonaws.com/yourobject
Hope it helps.
Disclaimer: I work for Minio

Download Log files from Amazon S3

I am having my bucket on Amazon S3 where I have uploaded certains files.
I have a sort public visitation on the page.
Is there any way to get the all visitations in log file
or Can I download the log file from the Amazon?
You can create logging for S3 bucket at the creation of bucket itself also after creating bucket. You need to specify the path for log file to store.You can refer http://docs.aws.amazon.com/AmazonS3/latest/UG/ManagingBucketLogging.html for steps.