The Serverless E-Store Backend is an implementation of a serverless backend for an e-commerce website. Functionalities are split across multiple micro-services that communicate through APIs.
This project is as an inspiration on how to build event-driven serverless microservice on AWS. This makes lots of assumptions on the order flow suitable for most e-commerce platform.
Please note that you may incure AWS charges for deploying the ecommerce platform into your AWS account as not all services used are part of the free tier and you might exceed the free tier usage limit. To track costs in your AWS account, consider using AWS Cost Explorer and AWS Billing and Cost Management. You can also set up a billing alarm to get notified of unexpected charges.
You can explore the Live REST API
- There are two users with usernames
admin
anduser
with same password123456
admin
has full privileges which includes managing products and usersuser
has privileges of managing only products
- REST API and CRUD endpoints using AWS Lambda, API Gateway
- User authentication/authorization and verification using AWS Cognito and Amazon Simple Email Service (SES)
- Data persistence with AWS DynamoDB and AWS S3
- Cloud stack development with Infrastructure as code (IaC) using AWS CloudFormation and AWS Cloud Development Kit (AWS CDK)
- Payment processing using Stripe APIs and Webhooks
- Test Driven Development (TDD)
This is a high-level view of how the different microservice interact with each other.
Communication/Messaging:
- Amazon API Gateway for service-to-service synchronous communication (request/response).
- Amazon Simple Email Service (SES) send immediate, trigger-based communications from your application to customers, such as account confirmations or password resets.
Authentication/Authorization:
- Amazon Cognito for managing and authenticating users, and providing JSON web tokens used by services.
- AWS Identity and Access Management for service-to-service authorization, either between microservices (e.g. authorize to call an Amazon API Gateway REST endpoint), or within a microservice (e.g. granting a Lambda function the permission to read from a DynamoDB table).
Compute:
- AWS Lambda as serverless compute either behind APIs or to react to asynchronous events.
Storage:
- Amazon DynamoDB as a scalable NoSQL database for persisting informations.
- Amazon S3 store data as objects within resources called “buckets” with features that include capabilities to append metadata tags to objects, move and store data.
CI/CD:
- AWS CloudFormation with AWS Serverless Application Model for defining AWS resources as code in most services.
- AWS Cloud Development Kit (CDK) for defining AWS resources as code.
Networking/Routing:
- AWS Route 53 scalable DNS and Domain Name Registration. It resolves domain names to it's equivalent IP address.
- AWS Certificate Manager (ACM) makes it easy to provision, manage, deploy, and renew SSL/TLS certificates
Management:
- AWS Systems Manager with Parameter Store provides a centralized store to manage your configuration data, whether plain-text data such as database strings or secrets such as passwords.
Monitoring:
- Amazon CloudWatch for metrics, dashboards, log aggregation.
Services | Description |
---|---|
auth | Gets user attributes for the current authenticated user. |
register | Registers and authenticates users. |
login | Logs in and authenticates users. |
logout | Logs out the current authenticated user. |
verify | Sends or verifies user using code sent via email. |
refresh | Refreshes tokens using refresh token from cookie. |
category | Gets supported product categories. |
country | Gets supported countries for delivery. |
products | Query/Search for products. |
product/{id} | Manages a product such creating, updating and deleting. |
order | Query/Search for orders. |
order/create | Manages an order such creating, updating and deleting. |
order/{intent} | Gets an order by intent such as cart or payment intent. |
payment/checkout | Checkouts an order. |
payment/hook | Webhook for updating payment processing. |
users | Gets users. |
user-group/{groupname} | Manages user groups such as adding and removing. |
Payment:
- Stripe | Payment Processing Platform with Webhooks notifies application using HTTPS when an event happens; used for asynchronous events such as when a customer’s bank confirms a payment, a customer disputes a charge, a recurring payment succeeds, or when collecting subscription payments.
Before getting started, make sure you have the following requirements:
- Your own Stripe account
- Your own AWS account
- An AWS user with Admin access and Programmatic Access
- The AWS Command Line Interface installed and configured for your user
- The AWS CDK Toolkit which is the primary tool for interacting with your AWS CDK app
- Node.js (v16 or higher)
- A bash compatible shell
Note: Make sure that your AWS Profile has been configured properly, run the below command to view profiles:
aws configure list-profiles
Follow these steps to get your development environment set up:
- Clone this repository locally;
# Change to the desired directory
$ cd <desired-directory>
# Clone the repo
$ git clone https://github.com/evanigwilo/e-store.git
# Change to the project directory
$ cd e-store
# Checkout to the server branch
$ git checkout server
# Install dependencies
npm install
-
Change AWS profile name in package.json file at
"cdk": "cdk --profile aws-cli-v2"
fromaws-cli-v2
to your configured profile name -
At the root directory, run below command:
npm run cdk -- deploy
-
Wait for provision of all microservices into aws cloud. That’s it!
-
At the root directory, in cdk-outputs.json file, the API url can be found with the key
apiUrl
Note: Make sure your Stripe API secret key and Webhook secret are stored in Parameter Store with the parameter name
stripe-secret
and keysstripe_api_secret_key
andwebhook_signing_secret
for webhooks to function properly.
I've hidden the values of my keys below, but this is the JSON we use to store our data for Stripe:
{
"stripe_api_secret_key":"sk_test_51JU2XXXXXXXXXXXX", // stripe API secret key
"webhook_signing_secret":"whsec_TqW4TXXXXXXXXXXXX", // stripe webhook signing secret
}
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testsnpm run cdk -- deploy
deploy this stack to your default AWS account/regionnpm run cdk -- diff
compare deployed stack with current statenpm run cdk -- synth
emits the synthesized CloudFormation templatenpm run cdk -- destroy
deletes the CloudFormation stacks created by this project