S3Ninja an Introduction

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,

"com.amazonaws" % "aws-java-sdk" % "1.10.30"

And Import the following packages as well,

import com.amazonaws.ClientConfiguration
import com.amazonaws.auth.{AWSCredentials, BasicAWSCredentials}
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.transfer.TransferManager

Create the AWS credentials with the help of Access key and Secret key provided by S3Ninja,

val credentials: AWSCredentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY)

After the credentials have been set, we can create the AmazonS3Client and set S3Ninja URL as an end point to it,

val NINJA_URL = "http://localhost:9444/s3"
val amazonS3Client: AmazonS3Client = new AmazonS3Client(credentials, new ClientConfiguration())

Now we set the client to the transfer manager,

val transferManager: TransferManager = new TransferManager(amazonS3Client)

Now we upload the file on S3Ninja as,

transferManager.upload(bucket, fileName, file)

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

About Harsh Sharma Khandal

Harsh is a Sr. Software Consultant at Knoldus Software LLP with 4 year of experience. He is a fan of programming standards and conventions. He has good knowledge of Scala, Java, 3D Modeling and 3D animation. His current passions include utilizing the power of Scala, Akka and Play to make reactive applications. He is a technologist and is never too far away from the keyboard. He believes in standard coding practices. His focus always remains on practical work. He has Master's in Computer Applications from Rajasthan Technical University, Kota. His hobbies include reading books and writing the code in multiple ways to find the best way it can be represented.
This entry was posted in integration, S3, s3ninja, Scala, tests and tagged , , , , , , , , , . Bookmark the permalink.

2 Responses to S3Ninja an Introduction

  1. Pingback: Integrating with S3Ninja | dotnetask

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s