Configuring AWS Credentials using Serverless Framework

Zero to Hero with Serverless: Tutorial Series — Part 01

Prasad Lakshan
5 min readJul 23, 2023
Figure 1.1 Configuring AWS Credentials using Serverless Framework

Welcome to the “Zero to Hero with Serverless” tutorial series on Medium! In this comprehensive guide, we will take you on a journey from being a beginner to becoming a serverless pro. In this first part, we will walk you through the process of setting up the Serverless Framework with AWS and configuring AWS credentials. So, let’s dive right in!

Introduction to Serverless Framework

The Serverless Framework is an open-source tool that allows developers to build, deploy, and manage serverless applications effortlessly. It supports various cloud providers, including Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform, and more.

With the Serverless Framework, you can define your application as a combination of small, focused functions that run in response to events. This approach enables you to focus on writing code without worrying about managing servers or infrastructure.

Prerequisites

Before we begin, make sure you have the following prerequisites in place:

  1. Node.js: Ensure you have Node.js installed on your computer. You can download it from the official website: https://nodejs.org
  2. AWS Account: You’ll need an AWS account to work with AWS services through the Serverless Framework.
  3. AWS CLI: Install the AWS Command Line Interface (CLI) on your system. You can find installation instructions at https://aws.amazon.com/cli/

Installing the Serverless Framework

To get started, open your terminal or command prompt and install the Serverless Framework globally using npm (Node Package Manager). The global installation allows you to access the serverless command from any directory in your system.

npm install -g serverless

Configuring AWS Credentials

Now that we have the Serverless Framework installed, we need to configure our AWS credentials. The Serverless Framework uses these credentials to interact with your AWS account, deploy services, and manage resources.

Creating an IAM User

It’s best practice to create a dedicated IAM (Identity and Access Management) user for the Serverless Framework. This way, you can grant specific permissions to this user without compromising the security of your AWS root account.

Setting Up the Serverless Framework with AWS — Configure AWS Credentials

Welcome to the “Zero to Hero with Serverless” tutorial series on Medium! In this comprehensive guide, we will take you on a journey from being a beginner to becoming a serverless pro. In this first part, we will walk you through the process of setting up the Serverless Framework with AWS and configuring AWS credentials. So, let’s dive right in!

Introduction to Serverless Framework

The Serverless Framework is an open-source tool that allows developers to build, deploy, and manage serverless applications effortlessly. It supports various cloud providers, including Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform, and more.

With the Serverless Framework, you can define your application as a combination of small, focused functions that run in response to events. This approach enables you to focus on writing code without worrying about managing servers or infrastructure.

Prerequisites

Before we begin, make sure you have the following prerequisites in place:

  1. Node.js: Ensure you have Node.js installed on your computer. You can download it from the official website: https://nodejs.org
  2. AWS Account: You’ll need an AWS account to work with AWS services through the Serverless Framework.
  3. AWS CLI: Install the AWS Command Line Interface (CLI) on your system. You can find installation instructions at https://aws.amazon.com/cli/

Installing the Serverless Framework

To get started, open your terminal or command prompt and install the Serverless Framework globally using npm (Node Package Manager). The global installation allows you to access the serverless command from any directory in your system.

npm install -g serverless

Configuring AWS Credentials

Now that we have the Serverless Framework installed, we need to configure our AWS credentials. The Serverless Framework uses these credentials to interact with your AWS account, deploy services, and manage resources.

Creating an IAM User

It’s best practice to create a dedicated IAM (Identity and Access Management) user for the Serverless Framework. This way, you can grant specific permissions to this user without compromising the security of your AWS root account.

  1. Sign in to your AWS Management Console.
  2. Navigate to the IAM service.
  3. Click on “Users” in the left sidebar and then click the “Add user” button.
  4. Enter a username for the new IAM user (e.g., “serverless-user”).
  5. Select “Programmatic access” as the access type.
  6. Click “Next: Permissions.”

Setting Permissions for the IAM User

In this step, we will attach an existing policy to the IAM user, granting the necessary permissions for deploying and managing serverless applications.

  1. Select “Attach existing policies directly.”
  2. Search for and select “AdministratorAccess” — This is a powerful policy that grants full access to AWS services. (Note: In a production environment, you should define more restrictive policies based on your application’s requirements.)

Review and Create

Review the user’s configuration to ensure everything is correct, then click “Create user.”

Access Key and Secret Key

Once the user is created, you’ll be provided with an Access Key ID and Secret Access Key. Make sure to copy and store these credentials securely. You will need them to configure the Serverless Framework.

Configuring Serverless with AWS Credentials

With the IAM user’s access keys in hand, open your terminal or command prompt and run the following command:

serverless config credentials --provider 
aws --key YOUR_ACCESS_KEY --secret YOUR_SECRET_KEY --profile YOUR_PROFILE_NAME

Replace YOUR_ACCESS_KEY ,YOUR_SECRET_KEY with the Access Key ID and Secret Access Key you obtained from the IAM user. And replace YOUR_PROFILE_NAME it with your preferred profile name. Keep in mind this profile name need to use in future.

Conclusion

Congratulations! You’ve successfully set up the Serverless Framework with AWS and configured your AWS credentials. In this tutorial, we learned the importance of creating a dedicated IAM user and assigning appropriate permissions to it. We also explored how to install the Serverless Framework and set up AWS credentials to interact with your AWS account.

In the next part of the “Zero to Hero with Serverless” series, we will dive into creating and deploying your first serverless function using the Serverless Framework. Stay tuned and happy serverless coding!

Remember, the Serverless Framework is a powerful tool that simplifies serverless application development, and it’s essential to follow best practices, especially when dealing with sensitive AWS credentials. Always ensure to keep your credentials secure and only grant the necessary permissions to your IAM users.

Thank you for reading, and I’ll see you in the next part of the series!

--

--

Prasad Lakshan

Tech enthusiast, passionate about exploring opportunities to learn, teach, help, and take experiences. 🌐 https://howtocodes.com