How to read data from S3 in a regular inetrval using Spark Scala

0 votes

I was trying to find application for my need and found one java application which dump data(in csv file) to s3 on daily basis.

This application create folder in S3 based on system date like(MM-DD-YYYY format) and then add files to the folder created.

Now i want to read those files from S3 on regular interval like

val fileFromS3= sc.textFile("s3a://digital/MM-DD-YYYY/abc.csv")

Now the script should replace 'MM-DD-YYYY' with the system date.

Please suggest possible solution or any other way to achieve this.

Oct 31, 2018 in AWS by findingbugs
• 3,260 points

1 answer to this question.

0 votes

Inorder to get it done first you need to import calender

First you need some imports:

import java.util.Calendar
import java.text.SimpleDateFormat
import java.util.Date
val now = Calendar.getInstance().getTime()  //you can get the current Time:
val formatter = new SimpleDateFormat("MM-dd-yyyy")
val dateAsString = formatter.format(now)   //use your formatter to get the date as String

Then you can load your resource with the dateAsString value using String interpolation:

val fileFromS3= sc.textFile(s"s3a://digital/${dateAsString}/abc.csv")
Hope this helps!

If you want to know more about Apache Spark Scala, It's highly recommended to go for Spark certification course today.


answered Oct 31, 2018 by Priyaj
• 58,140 points

Related Questions In AWS

+1 vote
2 answers

How to read a csv file stored in Amazon S3 using csv.DictReader

The code would be something like this: import ...READ MORE

answered Oct 25, 2018 in AWS by Archana
• 5,640 points
0 votes
1 answer

How to download the latest file in a S3 bucket using AWS CLI?

You can use the below command $ aws ...READ MORE

answered Sep 6, 2018 in AWS by Archana
• 4,150 points
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket.….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,140 points
0 votes
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,140 points
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,820 points
0 votes
2 answers
0 votes
1 answer

How to upload a file from S3 in Lambda?

Yes there is an option where you ...READ MORE

answered Jan 24, 2019 in AWS by Priyaj
• 58,140 points