S3Ninja is an emulator that emulates the S3API. S3Ninja provides an environment for your local system to support integration of upload a file, just as we do on S3. Currently it supports objects methods only like GET, PUT, HEAD, DELETE.
S3Ninja can be used,
- to upload file on our local system instead of S3
- to write integration tests that may integrate with upload of file on S3Ninja, instead of mocking the web services
Setting up S3Ninja
Follow the following steps to setup the S3Ninja emulator,
- Download S3Ninja latest version as ZIP file
- Unzip it to any directory
- Start S3Ninja by typing sirius.sh start
- Open the url http://localhost:9444 on browser
- Run S3 API calls on http://localhost:9444/s3 [e.g. -http://localhost:9444/s3/test-bucket ]
- After the use, stop S3Ninja by typing sirius.sh stop
Now we get the Access Key and Secret Key from the app/application.conf file in S3Ninja unzipped folder.
Lets begin the code
Include the following dependency into the build.sbt file for Amazon services,
And Import the following packages as well,
Create the AWS credentials with the help of Access key and Secret key provided by S3Ninja,
After the credentials have been set, we can create the AmazonS3Client and set S3Ninja URL as an end point to it,
Now we set the client to the transfer manager,
Now we upload the file on S3Ninja as,
Its done, Now you can open the URL http://localhost:9444/s3 on browser to verify the uploaded file
An example to verify to upload
The bucket demoBucket is created here,
The file ninja.jpg looks like this after upload.
I hope you enjoyed it!! Happy blogging!!
You can find complete code here
Nice article! Thanks