Testing with Amazon S3 and Postman

 

If you haven’t worked with S3 yet, it won’t be long until you do.

The following post will outline the simple steps required to read and write from an S3 bucket using postman. For the same steps using Java click here.

In order to access an S3 bucket, you will need access to an AWS account, If you don’t have an account and you want to proceed you can simply create a free tier account yourself. Creating your own AWS account is something I highly suggest as it will allow you to get more confidence with the AWS control panel.

Once you have access to an AWS account you will need the following

  1. AWS Access code
  2. AWS secret code
  3. Bucket name

The secret and access code can simply be generated within the AWS control panel.

In order to work with anything AWS, an AWS SDK is required, lucky for us, Postman has that built-in.

So let’s jump straight into our first request

 

List Buckets

GET –  http://s3.YOUR_REGION.amazonaws.com?list-type=2

Within the Authorisation tab, within the Type dropdown select AWS Signature. Be sure to enter your region and service name (S3)

The response will contain the name and creation date of each bucket

 

List files in a bucket

GET  –  http://YOUR_BUCKET.s3.YOUR_REGION.amazonaws.com?list-type=2

Hit send and you should see an XML response containing all files currently in that bucket

 

Add a file to a bucket

For this request will we be adding some test data. To keep things lets upload a simple text file

PUT  –  http://YOUR_BUCKET.s3.YOUR_REGION.amazonaws.com/testFile.txt

Add some tests in the body so as not to send an empty file

You would expect a 200 response with no body

 

Get a file’s contents from a bucket

For this request, let’s retrieve the contents of the file we just uploaded to S3

GET  –  http://YOUR_BUCKET.s3.YOUR_REGION.amazonaws.com/testFile.txt

The contents of the file will be returned int he response.

 

Delete a file content from a bucket

DELETE  –  http://YOUR_BUCKET.s3.YOUR_REGION.amazonaws.com/testFile.txt

here we are simply deleting the file that we had previously uploaded.

We would expect a 204 response code

Please follow and like us:

Leave a Reply

Your email address will not be published.