AWS- Serverless Deploy an S3 bucket and Upload Data

Raghav Jindal
3 min readApr 7, 2021

Set the serverless framework

You first have to set your machine to work as serverless. for that first, you have to create an IAM user name it serverless account and get it programmatic access with admin privileges Note the access key and secret key now go to your terminal window

  • npm install -g serverless
  • serverless config credentials — provider aws — key AKIAIOSFODNN7EXAMPLE — secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY — profile ServerlessUser

Create your first serverless project

Now we will create our first serverless project using AWS and node js. This will be a template project to get started with the AWS Lambda service. Get back to your terminal window and type the following commands

  • serverless create — template aws-nodejs — path myServerlessProject

You will get two files in that project the first one is handler.js and the other one is serverless.yml Add your profile name which you have written while writing the credentials in the serverless.fml file

Now open your terminal in the same directory and write

  • sls deploy

To check all this get back to your AWS account and in the console find the Lambda service. There you will find a new function named “myServerlessProject”

You need to have a serverless account setup on your machine and for that please see the previous article.

Creating S3 bucket

Open the servell.yml file and the following lines to it to create an s3 bucket.

Bucket name should be unique so that its more likely to be created without giving any errors at runtime.

Then Open the Terminal window and again type

  • sls deploy

Now go back to your AWS account and search for S3 on the console Inside the S3 dashboard, you will see a freshly created bucket with the name as you specified

Uploading data to S3 bucket

open your terminal and install the package

  • npm install — save serverless-s3-sync

Now open the serverless.yml file and write the following lines of code to it

This adds the plugin s3sync that basically synchronizes the data. Note two thing here

  1. bucketName should be the same as your bucket name which we have created earlier
  2. localdir — write the directory name of which the contents you want to upload in S3 bucket

now again open the terminal window and type

  • sls deploy

To check the working of this go back to your AWS account then get inside your S3 bucket you will find that all the files which were in your local directory are now inside the S3 bucket.

You can use these steps to work on two different projects:

  • Create as many buckets as the user needs within a single click.
  • Add multiple files into your bucket.

--

--

Raghav Jindal

Cloud Computing || MERN Stack Development || AWS || Penetration testing || AI & ML || Virtualization||Data Science