GithubHelp home page GithubHelp logo

aws-samples / aws-bookstore-demo-app Goto Github PK

View Code? Open in Web Editor NEW
607.0 31.0 306.0 16.54 MB

AWS Bookstore Demo App is a full-stack sample web application that creates a storefront (and backend) for customers to shop for fictitious books. The entire application can be created with a single template. Built on AWS Full-Stack Template.

License: MIT No Attribution

HTML 1.38% CSS 8.97% JavaScript 19.95% Python 4.94% TypeScript 64.76%

aws-bookstore-demo-app's Introduction

AWS Bookstore Demo App

AWS Bookstore Demo App is a full-stack sample web application that creates a storefront (and backend) for customers to shop for fictitious books. The entire application can be created with a single CloudFormation template. Try out the deployed application here!

You can browse and search for books, look at recommendations and best sellers, manage your cart, checkout, view your orders, and more. Get started with building your own below!  

License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.

 

Outline

 

Overview

The goal of AWS Bookstore Demo App is to provide a fully-functional web application that utilizes multiple purpose-built AWS databases and native AWS components like Amazon API Gateway and AWS CodePipeline. Increasingly, modern web apps are built using a multitude of different databases. Developers break their large applications into individual components and select the best database for each job. Let's consider AWS Bookstore Demo App as an example. The app contains multiple experiences such a shopping cart, product search, recommendations, and a top sellers list. For each of these use cases, the app makes use of a purpose-built database so the developer never has to compromise on functionality, performance, or scale.

The provided CloudFormation template automates the entire creation and deployment of AWS Bookstore Demo App. The template includes the following components:

Database components

  • Product catalog/shopping cart - Amazon DynamoDB offers fast, predictable performance for the key-value lookups needed in the product catalog, as well as the shopping cart and order history. In this implementation, we have unique identifiers, titles, descriptions, quantities, locations, and price.
  • Search - Amazon Elasticsearch Service enables full-text search for our storefront, enabling users to find products based on a variety of terms including author, title, and category.
  • Recommendations - Amazon Neptune provides social recommendations based on what user's friends have purchased, scaling as the storefront grows with more products, pages, and users.
  • Top sellers list - Amazon ElastiCache for Redis reads order information from Amazon DynamoDB Streams, creating a leaderboard of the “Top 20” purchased or rated books.

Application components

  • Serverless service backend – Amazon API Gateway powers the interface layer between the frontend and backend, and invokes serverless compute with AWS Lambda.
  • Web application blueprint – We include a React web application pre-integrated out-of-the-box with tools such as React Bootstrap, Redux, React Router, internationalization, and more.

Infrastructure components

  • Continuous deployment code pipeline – AWS CodePipeline and AWS CodeBuild help you build, test, and release your application code.
  • Serverless web application – Amazon CloudFront and Amazon S3 provide a globally-distributed application.

You can choose to customize the template to create your own bookstore, modify it to make a different type of store, or change it to make a completely different type of web application.

AWS Bookstore Demo App is built on-top of AWS Full-Stack Template, which provides the foundational services, components, and plumbing needed to get a basic web application up and running. Users can build on top of AWS Full-Stack Template to create any application they envision, whether a travel booking tool, a blog, or another web app. This AWS Bookstore Demo App is just one example of what you can create using AWS Full-Stack Template.

Watch the recorded talk and demo here.  


 

Instructions

IMPORTANT NOTE: Creating this demo application in your AWS account will create and consume AWS resources, which will cost money. We estimate that running this demo application will cost ~$0.45/hour with light usage. Be sure to shut down/remove all resources once you are finished to avoid ongoing charges to your AWS account (see instructions on cleaning up/tear down below).

 

Getting started

To get AWS Bookstore Demo App up and running in your own AWS account, follow these steps (if you do not have an AWS account, please see How do I create and activate a new Amazon Web Services account?):

  1. Log into the AWS console if you are not already.
    Note: If you are logged in as an IAM user, ensure your account has permissions to create and manage the necessary resources and components for this application.
  2. Choose one of the Launch Stack buttons below for your desired AWS region to open the AWS CloudFormation console and create a new stack. AWS Bookstore Demo App is supported in the following regions:
Region name Region code Launch
US East (N. Virginia) us-east-1 Launch Stack
US West (Oregon) us-west-2 Launch Stack
EU (Ireland) eu-west-1 Launch Stack
EU (Frankfurt) eu-central-1 Launch Stack
  1. Continue through the CloudFormation wizard steps
    1. Name your stack, e.g. MyBookstore
    2. Provide a project name (must be lowercase, letters only, and under twelve (12) characters). This is used when naming your resources, e.g. tables, search domain, etc.
    3. After reviewing, check the blue box for creating IAM resources.
  2. Choose Create stack. This will take ~20 minutes to complete.
  3. Once the CloudFormation deployment is complete, check the status of the build in the CodePipeline console and ensure it has succeeded.
  4. Sign into your application
    1. The output of the CloudFormation stack creation will provide a CloudFront URL (in the Outputs table of your stack details page). Click the link or copy and paste the CloudFront URL into your browser.
    2. You can sign into your application by registering an email address and a password. Choose Sign up to explore the demo to register. The registration/login experience is run in your AWS account, and the supplied credentials are stored in Amazon Cognito. Note: given that this is a demo application, we highly suggest that you do not use an email and password combination that you use for other purposes (such as an AWS account, email, or e-commerce site).
    3. Once you provide your credentials, you will receive a verification code at the email address you provided. Upon entering this verification code, you will be signed into the application.

 

Advanced: The source CloudFormation template is available here. If you want to maintain low latency for your app, this deeplink will create an identical stack, but with additional triggers to keep the Lamdba functions "warm" (CloudFormation template here). For more information, see the Considerations for demo purposes section.

 

Cleaning up

To tear down your application and remove all resources associated with AWS Bookstore Demo App, follow these steps:

  1. Log into the Amazon S3 Console and delete the buckets created for the demo app.
    • There should be two buckets created for AWS Bookstore Demo App. The buckets will be titled "X" and "X-pipeline", where "X" is the name you specified in the CloudFormation wizard under the AssetsBucketName parameter.
    • Note: Please be very careful to only delete the buckets associated with this app that you are absolutely sure you want to delete.
  2. Log into the AWS CloudFormation Console and find the stack you created for the demo app
  3. Delete the stack

Remember to shut down/remove all related resources once you are finished to avoid ongoing charges to your AWS account.

 


 

Architecture

Summary diagram

Summary Diagram

 

High-level, end-to-end diagram

High-level Architectural Diagram

 

Frontend

Build artifacts are stored in a S3 bucket where web application assets are maintained (like book cover photos, web graphics, etc.). Amazon CloudFront caches the frontend content from S3, presenting the application to the user via a CloudFront distribution. The frontend interacts with Amazon Cognito and Amazon API Gateway only. Amazon Cognito is used for all authentication requests, whereas API Gateway (and Lambda) is used for all API calls interacting across DynamoDB, Elasticsearch, ElastiCache, and Neptune.

Backend

The core of the backend infrastructure consists of Amazon Cognito, Amazon DynamoDB, AWS Lambda, and Amazon API Gateway. The application leverages Amazon Cognito for user authentication, and Amazon DynamoDB to store all of the data for books, orders, and the checkout cart. As books and orders are added, Amazon DynamoDB Streams push updates to AWS Lambda functions that update the Amazon Elasticsearch cluster and Amazon ElasticCache for Redis cluster. Amazon Elasticsearch powers search functionality for books, and Amazon Neptune stores information on a user's social graph and book purchases to power recommendations. Amazon ElasticCache for Redis powers the books leaderboard.

Backend Diagram

 

Developer Tools

The code is hosted in AWS CodeCommit. AWS CodePipeline builds the web application using AWS CodeBuild. After successfully building, CodeBuild copies the build artifacts into a S3 bucket where the web application assets are maintained (like book cover photos, web graphics, etc.). Along with uploading to Amazon S3, CodeBuild invalidates the cache so users always see the latest experience when accessing the storefront through the Amazon CloudFront distribution. AWS CodeCommit. AWS CodePipeline, and AWS CodeBuild are used in the deployment and update processes only, not while the application is in a steady-state of use.

Developer Tools Diagram

 


 

Implementation details

Note: The provided CloudFormation template contains only a portion of the resources needed to create and run the application. There are web assets (images, etc.), Lambda functions, and other resources called from the template to create the full experience. These resources are stored in a public-facing S3 bucket and referenced in the template.

 

Amazon DynamoDB

The backend of AWS Bookstore Demo App leverages Amazon DynamoDB to enable dynamic scaling and the ability to add features as we rapidly improve our e-commerce application. The application create three tables in DynamoDB: Books, Orders, and Cart. DynamoDB's primary key consists of a partition (hash) key and an optional sort (range) key. The primary key (partition and sort key together) must be unique.

Books Table:

BooksTable {
  id: string (primary partition key)
  author: string
  category: string (index, GSI)
  cover: string (url to s3 file)
  name: string 
  price: number
  rating: number
}

The table's partition key is the ID attribute of a book. The partition key allows you to look up a book with just the ID. Additionally, there is a global secondary index (GSI) on the category attribute. The GSI allows you to run a query on the category attribute and build the books by category experience.

For future updates to the application, we plan to return the results of a search/filter by category via Elasticsearch. Additionally, there is no “description” attribute, as this sample application does not feature pages for individual books. This may be something users wish to add.

 

Orders Table:

OrdersTable {
    customerId: string (primary partition key)
    orderId: string (uuid, primary sort key)
    books: bookDetail[]
    orderDate: date 
}
bookDetail {
    bookId: string
    customerId: string
    quantity: number
    price: number
}

The order table's partition key is the customer ID. This allows us to look up all orders of the customer with just their ID.

 

Cart Table:

CartTable {
    customerId: string (primary partition key)
    bookId: string (uuid, primary sort key)
    price: number
    quantity: number
}

The cart table stores information about a customer's saved cart.

 

Amazon API Gateway

Amazon API Gateway acts as the interface layer between the frontend (Amazon CloudFront, Amazon S3) and AWS Lambda, which calls the backend (databases, etc.). Below are the different APIs the application uses:

Books (DynamoDB)

GET /books (ListBooks)
GET /books/{:id} (GetBook)

Cart (DynamoDB)

GET /cart (ListItemsInCart)
POST /cart (AddToCart)
PUT /cart (UpdateCart)
DELETE /cart (RemoveFromCart)
GET /cart/{:bookId} (GetCartItem)

Orders (DynamoDB)

GET /orders (ListOrders)
POST /orders (Checkout)

Best Sellers (ElastiCache)

GET /bestsellers (GetBestSellers)

Recommendations (Neptune)

GET /recommendations (GetRecommendations)
GET /recommendations/{bookId} (GetRecommendationsByBook)

Search (Elasticsearch)

GET /search (SearchES)

 

AWS Lambda

AWS Lambda is used in a few different places to run the application, as shown in the architecture diagram. The important Lambda functions that are deployed as part of the template are shown below, and available in the functions folder. In the cases where the response fields are blank, the application will return a statusCode 200 or 500 for success or failure, respectively.

 

ListBooks Lambda function that lists the books in the specified product category

ListBooksRequest {
    category?: string (optional parameter)  
}
ListBooksResponse {
    books: book[]
}
book {
    id: string
    category: string
    name: string 
    author: string
    description: string
    rating: number
    price: number
    cover: string
}

 

GetBook Lambda function that will return the properties of a book.

GetBookRequest {
  bookId: string
}
GetBookResponse {
    id: string
    category: string
    name: string 
    author: string
    description: string
    rating: number
    price: number
    cover: string
}

 

ListItemsInCart Lambda function that lists the orders a user has placed.

ListItemsInCartRequest {

}
ListItemsInCartResponse {
    orders[]
}
order {
    customerId: string
    bookId: string
    quantity: number
    price: number
}

 

AddToCart Lambda function that adds a specified book to the user's cart. Price is included in this function's request so that the price is passed into the cart table in DynamoDB. This could reflect that the price in the cart may be different than the price in the catalog (i.e. books table) perhaps due to discounts or coupons.

AddToCartRequest {
    bookId: string
    quantity: number
    price: number
}
AddToCartResponse {

}

 

RemoveFromCart Lambda function that removes a given book from the user's cart.

RemoveFromCartRequest {
    bookId: string
}
RemoveFromCartResponse {

}

 

GetCartItem Lambda function that returns the details of a given item the user's cart.

GetCartItemRequest {
    bookId: string
}
GetCartItemResponse {
    customerId: string
    bookId: string
    quantity: number
    price: number
}

 

UpdateCart Lambda function that updates the user's cart with a new quantity of a given book.

UpdateCartRequest {
    bookId: string
    quantity: number
}
UpdateCartResponse {
    
}

 

ListOrders Lambda function that lists the orders for a user.

ListOrdersRequest {

}
ListOrdersResponse {
    customerId: string 
    orderId: string
    orderDate: date
    books: bookDetail[]
}
bookDetail {
    bookId: string
    price: number
    quantity: number
}

 

Checkout Lambda function that moves the contents of a user's cart (the books) into the checkout flow, where you can then integrate with payment, etc.

CheckoutRequest {
    books: bookDetail[]
}
bookDetail {
    bookId: string
    price: number
    quantity: number
}
CheckoutResponse {

}

In addition to the above, the Checkout Lambda function acts as a sort of mini-workflow with the following tasks:

  1. Add all books from the Cart table to the Orders table
  2. Remove all entries from the Cart table for the requested customer ID

 

GetBestSellers Lambda function that returns a list of the best-sellers.

GetBestSellersRequest {

}
GetBestSellersResponse {
    bookIds: string[]
}

 

GetRecommendations Lambda function that returns a list of recommended books based on the purchase history of a user's friends.

GetRecommendationsRequest {

}
GetRecommendationsResponse {
    recommendations: recommendation[]
}
recommendation {
    bookId: string
    friendsPurchased: customerId[]
    purchases: number
}
customerId: string

 

GetRecommendationsByBook Lambda function that returns a list of friends who have purchased this book as well as the total number of times it was purchased by those friends.

GetRecommendationsByBookRequest {
    bookId: string
}
GetRecommendationsByBookResponse {
    friendsPurchased: customerId[]
    purchased: number
}
customerId: string

 

Other Lambda functions There are a few other Lambda functions used to make AWS Bookstore Demo App work, and they are listed here:

  1. Search - Lambda function that returns a list of books based on provided search parameters in the request.
  2. updateSearchCluster - Lambda function that updates the Elasticsearch cluster when new books are added to the store.
  3. updateBestsellers - Updates Leaderboard via the ElastiCache for Redis cluster as orders are placed.

 

Amazon ElastiCache for Redis

Amazon ElastiCache for Redis is used to provide the best sellers/leaderboard functionality. In other words, the books that are the most ordered will be shown dynamically at the top of the best sellers list.

For the purposes of creating the leaderboard, AWS Bookstore Demo App utilized ZINCRBY, which “Increments the score of member in the sorted set stored at key byincrement. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.”

The information to populate the leaderboard is provided from DynamoDB via DynamoDB Streams. Whenever an order is placed (and subsequently created in the Orders table), this is streamed to Lambda, which updates the cache in ElastiCache for Redis. The Lambda function used to pass this information is UpdateBestSellers.

 

Amazon Neptune

Neptune provides a social graph that consists of users, books. Recommendations are only provided for books that have been purchased (i.e. in the list of orders). The “top 5” book recommendations are shown on the bookstore homepage.

 

Amazon Elasticsearch

Amazon Elasticsearch Service powers the search capability in the bookstore web application, available towards the top of every screen in a search bar. Users can search by title, author, and category. The template creates a search domain in the Elasticsearch service.

It is important that a service-linked role is created first (included in the CloudFormation template).

 

AWS IAM

ListBooksLambda AWSLambdaBasicExecutionRole
dynamodb:Scan - table/Books/index/category-index
dynamodb:Query - table/Books

GetBookLambda AWSLambdaBasicExecutionRole
dynamodb:GetItem - table/Books

ListItemsInCartLambda AWSLambdaBasicExecutionRole
dynamodb:Query - table/Cart

AddToCartLambda AWSLambdaBasicExecutionRole
dynamodb:PutItem - table/Cart

UpdateCartLambda AWSLambdaBasicExecutionRole
dynamodb:UpdateItem - table/Cart

ListOrdersLambda AWSLambdaBasicExecutionRole
dynamodb:Query - table/Orders

CheckoutLambda AWSLambdaBasicExecutionRole
dynamodb:PutItem - table/Orders
dynamoDB:DeleteItem - table/Cart

 

Amazon Cognito

Amazon Cognito handles user account creation and login for the bookstore application. For the purposes of the demo, the bookstore is only available to browse after login, which could represent the architecture of different types of web apps. Users can also choose to separate the architecture, where portions of the web app are publicly available and others are available upon login.

User Authentication

  • Email address

Amazon Cognito passes the CognitoIdentityID (which AWS Bookstore Demo app uses as the Customer ID) for every user along with every request from Amazon API Gateway to Lambda, which helps the services authenticate against which user is doing what.

 

Amazon CloudFront and Amazon S3

Amazon CloudFront hosts the web application frontend that users interface with. This includes web assets like pages and images. For demo purposes, CloudFormation pulls these resources from S3.

 

Amazon VPC

Amazon VPC (Virtual Private Cloud) is used with Amazon Elasticsearch Service, Amazon ElastiCache for Redis, and Amazon Neptune.

 

Amazon CloudWatch

The capabilities provided by CloudWatch are not exposed to the end users of the web app, rather the developer/administrator can use CloudWatch logs, alarms, and graphs to track the usage and performance of their web application.

 

AWS CodeCommit, AWS CodePipeline, AWS CodeBuild

Similar to CloudWatch, the capabilities provided by CodeCommit, CodePipeline, and CodeBuild are not exposed to the end users of the web app. The developer/administrator can use these tools to help stage and deploy the application as it is updated and improved.

 


 

Running your web application locally

  1. If you haven't setup Git credentials for AWS CodeCommit before, head to the IAM Console. If you have already you can skip to step 5.

  2. Choose your IAM user.

  3. Choose the Security credentials tab. Scroll to the bottom and choose Generate underneath HTTPS Git credentials for AWS CodeCommit.

  4. Download and save these credentials. You will use these credentials when cloning your repository.  

  5. Go to the CodeCommit console and find your code repository.

  6. Choose the HTTPS button underneath the Clone URL column.

  7. Open up your terminal, type git clone paste the Clone URL and hit enter.  

  8. Once the repository has created, run npm install.

  9. After all dependencies have been downloaded, run npm run start.  

You're done! Any future updates you make to your repository will get pushed to your code pipeline automatically and published to your web application endpoint.

 


 

Considerations for demo purposes

  1. In order to make AWS Bookstore Demo App an effective demonstration from the moment it is created, the CloudFormation template kicks off a Lambda function we wrote to pre-load a list of books into the product catalog (the Books table in DynamoDB). In the same way, we used a Lambda function to pre-load sample friends (into Neptune) and manually populated the list of Best Sellers (on the front page only). This enables you to sign up as a new user and immediately see what the running store would look like, including recommendations based on what friends have purchased and what the best-selling books section does.

  2. You will notice that the Past orders and Best sellers pages are empty at first run. These are updated as soon as an order is placed.

  3. For the purposes of this demo, we did not include a method to add or remove friends, and decided that every new user will be friends with everyone else (not the most realistic, but effective for this demo). You are welcome to play around with changing this, adding friend control functionality, or manually editing friendships via the bookstore-friends-edges.csv file.

  4. Web assets (pages, images, etc.) are pulled from a public S3 bucket via the CloudFormation template to create the frontend for AWS Bookstore Demo App. When building your own web application (or customizing this one), you will likely pull from your own S3 buckets. If you customize the lambda functions, you will want to store these separately, as well.

  5. Checkout is a simplified demo experience that customers can take and implement a real-world payment processing platform. Similarly, the View Receipt button after purchase is non-functional, meant to demonstrate how you can add on to the app.

  6. The CloudFormation template referenced in #2 of the Getting started section is everything you need to create the full-stack application. However, when the application is newly created, or hasn't been used in some time, it may take a few extra seconds to run the Lamdba functions, which increases the latency of operations like search and listing books. If you want to maintain low latency for your app, this deeplink creates an identical stack but with additional triggers to keep the Lamdba functions "warm." Given that these triggers make the Lamdba functions run more frequently (every 10 minutes, on a schedule), this will add a small amount to the overall cost to run the application. The benefit is a more responsive application even when the Lamdba functions are not being regularly called by user activity.

 


 

Known limitations

  • The application was written for demonstration purposes and not for production use.
  • Orders are backed by DynamoDB, but no mechanism exists to recreate the best sellers list in the unlikely scenario of a Redis failure.
  • Upon the first use of a Lambda function, cold start times in a VPC can be slow. Once the Lambda function has been warmed up, performance will improve. See #6 in Considerations for demo purposes for more information.
  • The application is not currently designed for for high availability. You can increase the availability of the application by configuring the Amazon Elasticsearch, Amazon Neptune, and Amazon ElastiCache clusters with multiple instances across multiple AZs.
  • The application enables multiple users to sign into the application but the social graph is single user. As a result, different users will see the same social graph. Further, when new books are purchased, that state is not reflected in the social graph.
  • There are some network errors observed on Firefox. We are looking into this.

 


 

Additions, forks, and contributions

We are excited that you are interested in using AWS Bookstore Demo App! This is a great place to start if you are just beginning with AWS and want to get a functional application up and running. It is equally useful if you are looking for a sample full-stack application to fork off of and build your own custom application. We encourage developer participation via contributions and suggested additions. Of course you are welcome to create your own version!

Please see the contributing guidelines for more information.

For a more basic example of a full-stack web application, check out AWS Full-Stack Template upon which AWS Bookstore Demo App was built. As mentioned in the Overview section, AWS Full-Stack Template provides the foundational services, components, and plumbing needed to get a basic web application up and running. Users can build on top of AWS Full-Stack Template to create any application they envision, whether a travel booking tool, a blog, or another web app. This AWS Bookstore Demo App is just one example of what you can create using AWS Full-Stack Template.

 


 

Questions and contact

For questions on AWS Bookstore Demo App, or to contact the team, please leave a comment on GitHub.

aws-bookstore-demo-app's People

Contributors

adilmujeeb avatar alexcasalboni avatar j13d avatar jpeddicord avatar lpiedade avatar matheuscanela avatar rbboimer avatar smohiuddin avatar triggan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-bookstore-demo-app's Issues

Is there a github repo to PR against books.json for the demo?

There are several great books that could be added to the sample dataset, including such classics as:

The Invisible TAM
The Book of Job Scheduling
Stranger in a Strange LAN
20000 Leagues Under the C
The Site Down and the Fury
Prometheus IO Bound
A Cloud Flew Over the Cuckoo’s Nest
The Callback of the Wild
A Song of Ice and Tirefire
Senders Game
All Quiet on the Western Cloudfront
Infinite Jeffs
JSON and the Golden Fleece
The Segfault in Our Stars
Us-East-1 of Eden
The Datalakes of Wrath
Paradise Tossed
The Sun Also Crashes
The Old Man and the C

"Error: Network Error"

Describe the bug
Getting a "Error: Network Error" pop up message when loading the "main" webpage after log in. Seems to be a CORS issue:
"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://yuq7ws39pj.execute-api.us-east-1.amazonaws.com/prod/recommendations. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 502."

To Reproduce
Steps to reproduce the behavior:

  1. Log in
  2. Load the webpage (https://d2h3ljlsmzojxz.cloudfront.net/)

Expected behavior
Expected no error

Screenshots
error

Desktop (please complete the following information):

  • Firefox

Add mappings to other regions or static reference to S3Bucket w/o AWS::region as it only exist in us-east-1..

Hello,

When trying to deploy to different regions, there's an error returned.
After digging into the CFN template, it seems that there's only a bucket for the assets in us-east-1, but in references to the S3Bucket mapping, the template maps AWS::Region, like so:
S3Bucket: !FindInMap
- S3Buckets
- !Ref 'AWS::Region'
- Bucket

Suggest to keep the region static or deploy the code in buckets on other regions.

Codepipeline build stage failing with "Package 'graphql' support only TS versions that are >=4.1.0"

Codepipeline build stage is failing with "Package 'graphql' support only TS versions that are >=4.1.0". Here is the complete error. Any quick fixes I can try ?

Creating an optimized production build...
Failed to compile.

/codebuild/output/src957309149/src/node_modules/graphql/NotSupportedTSVersion.d.ts
TypeScript error in /codebuild/output/src957309149/src/node_modules/graphql/NotSupportedTSVersion.d.ts(1,63):
Identifier expected. TS1003

1 | "Package 'graphql' support only TS versions that are >=4.1.0".
| ^

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: react-scripts build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-11-07T22_47_43_594Z-debug.log

[Container] 2021/11/07 22:47:43 Command did not exit successfully npm run build exit status 1
[Container] 2021/11/07 22:47:43 Phase complete: BUILD State: FAILED

UpdateSearchCluster lambda: Unable to import module 'index': No module named index

Describe the bug
When updating an item DynamoDB Streams should update the search index. However next to the trigger in the table is shown PROBLEM: Function call failed and looking at the CloudWatch logs of UpdateSearchCluster lambda shows Unable to import module 'index': No module named index

To Reproduce
Steps to reproduce the behavior:

  1. Do a fresh deployment in us-east-1
  2. Modify some item
  3. Look at the trigger/ cloudwatch logs of UpdateSearchCluster lambda function

Expected behavior
No error message.

CloudFormation deployment fails as a result of Python 2.7 runtime deprecation

Describe the bug
CFN stack deployment fails to create Lambda function UpdateSearchCluster with the following error:

"The runtime parameter of python2.7 is no longer supported for creating or updating AWS Lambda functions. We recommend you use the new runtime (python3.9) while creating or updating functions."

I edited the CFN YAML and changed it to Python 3.8, and the stack deploys successfully, but the UpdateSearchCluster function fails to execute with this error:

"Syntax error in module 'index': Missing parentheses in call to 'print'. Did you mean print("bookId " + id)? (index.py, line 25)"

This appears to be related to syntax changes between Python version 2 and 3.

Images in the store are very big (on s3)

Describe the bug
The item images are very big (1-2mb each),
as a result, it takes time to render the page and the result seems sluggish.
The purpose of this demo is to give a "Right database tool for the job" demo, but when showing the demo, it gives the impression of a slow sluggish app - hench it's not a good show.. :)

Also, you're using Cloudfront to serve the app, why not add another behaviour to cache objects from S3 rather then directly linking to an S3 bucket? this should also speed things up.

To Reproduce
Just move and load diffrent categories of items in the app,
Each image takes long time to load.

Expected behavior
faster page load times.

Thank you

Implement Friend recommendations

Is your feature request related to a problem? Please describe.
Its hard to demo the recommendation engine because there's no notion of friends in the system,
also - i didn't see and insert into neptune in the code.

Describe the solution you'd like
I'd like to see that if two different users buy a book, it will show that a friend has bought it.
also it would be nice to get recommendations upon checkin out - do you want to add this book too?

Homepage signup doesn't work (AccessDenied)

Describe the bug
When you click on the "Sign up to explore the demo" button you land on /signup (which doesn't exist).

Note: the "Sign up" link in the top navbar works fine.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the home page (as anonymous user)
  2. Click on 'Sign up to explore the demo'
  3. See error

Expected behavior
An in-page route is shown (with the signup form).

bookstoreNeptuneLoader does not delete cleanly upon stack deletion

Describe the bug
When deleting the CloudFormation stack, the bookstoreNeptuneLoader Custom CloudFormation resource does not delete cleanly. This appears to be related to a dependency on the two VPC Route Table Associations. The Route Table Associations for the two VPC subnets are being deleted before the bookstoreNeptuneLoader Custom CloudFormation resource can reply back to the CloudFormation service that a DELETE action has been received (requires an HTTPS connection from the Lambda function to an S3 HTTPS endpoint).

In order to fix this issue, we need to add a DependsOn entry for both of the following Resources on to the bookstoreNeptuneLoader Resource:
bookstoreVPCRouteTableAssociation
bookstoreVPCRouteTableAssociationTwo

To Reproduce
Steps to reproduce the behavior:
Every creation and deletion of a stack.

Expected behavior
Complete stack deletes without issue when a delete command is made.

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
N/A

Link to recorded talk

It would be very helpful to have the link to the talk(s) where this demo is presented in the readme.

CloudFormation wizard give error

Followed the Readme steps and while creating the stack using US West (Oregon) LaunchStack, it failed with error "Resource creation cancelled".
Possible Root cause gives below information:
"Properties validation failed for resource BestsellersApiRequestOPTIONS with message: #/AuthorizationType: #: only 1 subschema matches out of 2 #/AuthorizationType: failed validation constraint for keyword [enum]"

What is the reason of this error?

Add a Built-In Cognito User

Is your feature request related to a problem? Please describe.
To ensure access to the site without needing to register a new account, we should add a built-in Cognito user. This avoids potential problems if the 2F registration emails get caught by spam filters or otherwise.

Search not displaying results

Describe the bug
Search not displaying results in webpage, but can see results are being returned by lambda function when testing through Search API or viewing cloudwatch logs for Lambda Function.

To Reproduce
Steps to reproduce the behavior:

  1. Search for any known book in database
  2. Click enter or hit Search

Expected behavior
Search results should be displayed on webspage

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome

Deployment on cloud Formation.

As i'm trying to follow the steps in getting started. it shows me a rollback error of the lambs functions. is there any other way to run the code.

Template linked in advanced section does not match the one in the git repo

In this section in readme.md its mentioned:

Advanced: The source CloudFormation template is available here. and links to:

https://s3.amazonaws.com/aws-bookstore-demo/master-fullstack.template

but the template there is not the same as the one on this repo (for example the constants section is shorter)..

Category view results in Access Denied error

Describe the bug
The category view e.g. https://mydistname.cloudfront.net/category/Cars results in an Access Denied error.

<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>012345</RequestId><HostId>R2oclEoKzgck7Jw/5rBKjXDjqKV0bOtBZrBzfttfnvanUu9KK/kbZmeOWXdrz6X9IGVfSk=</HostId></Error>

To Reproduce
Steps to reproduce the behavior:

  1. Navigate to Index page
  2. Click on one of the categories in the Navigation bar
  3. AccessDenied error will appear

Expected behavior
Books in the selected category are shown

Add support for x-ray

Is your feature request related to a problem? Please describe.
This is a great showcase of an e2e demo application built upon AWS resources. It would be even better if it was instrumented with x-ray out of the box.

Describe the solution you'd like

  • Add AWS instrumentation for Node/Python lambdas using http capture API.
  • Enable x-ray tracing by default on all resources (e.g: api gateway, lambda, etc)

Describe alternatives you've considered
I've gone through and done some of this work myself but it's time consuming given the cloudformation setup uses prebuilt assets from s3. This pain could be reduced if the current setup used CodePipeline to build and deploy the lambda artifacts on demand.

Also worth noting the redis client used in Node.js doesn't support cls under the hood. Would require migrating to ioredis. This may be mitigated by cls_hooked

Additional context
N/A

Add frontend source code?

Is it possible to add the frontend source code, plus a couple of guidelines on how to integrate the backend serverless components with the front end?

I am building a project and researching going serverless and it would be really valuable.

Thank you.

assets fail to create from stack for eu-central-1

Stack creation fails for 2 assets, bookstoreNeptuneLoader and BooksUploader, on eu-central-1. as far as I can see there is a problem accessing a public s3 bucket for some node modual in aws-sdk. im not certin if there is some problem with settings on my account that prevent that bucket from being accessed or there is a problem with the stack template itself.

log snippet of the error:

2022-10-31T13:17:34.177Z 3e2dc1b4-716d-48e4-87b9-2b00108ee0e2 INFO AccessDenied: Access Denied
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/services/s3.js:710:35)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:686:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:688:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 'AccessDenied',
region: null,
time: 2022-10-31T13:17:34.117Z,
requestId: '59E0FHNJ3A602C4T',
extendedRequestId: 'JbFqg75W3vJ+ey7aj8IlKvDnRoOq07dVV7wW7OlYZXWFw8bpOKAkBzj0AJczeZZGe8gR5UNceTI=',
cfId: undefined,
statusCode: 403,
retryable: false,
retryDelay: 19.55702681850291
}

i just tried to create the stack on eu-central-1, no changes to anything just ran the stack. any help would be greatly appriciated.

AWS-bookstore-demo-app failing to deploy

The template would't deploy due to limitted access to sd-aws-wildrydes-us-west-2/aws-serverless-codecommit-seeder.zip.

Cloudformation Error:

CREATE_FAILED | Resource handler returned message: "Your access has been denied by S3, please make sure your request credentials have permission to GetObject for fsd-aws-wildrydes-us-west-2/aws-serverless-codecommit-seeder.zip. S3 Error Code: AccessDenied. S3 Error Message: Access Denied (Service: Lambda, Status Code: 403, Request ID: 807f6f50-152f-49e2-b2e2-8848d6376073, Extended Request ID: null)" (RequestToken: 0b0a339e-fb38-550c-b2ae-2d9d2605a2b9, HandlerErrorCode: AccessDenied)

This is causing SeederFunction to fail to deploy.

To reproduce, simply deploy the the project with cloudformation.
Screen Shot 2021-12-21 at 4 02 23 PM

How to run this in local env for development?

The react app seems to run locally, but it connects to AWS for Cognito and Lambda functions, how to unit test those services (build, debug, test cycle)?

Where is the code for those lambda functions btw, couldn't find it in this repository?

Neptune query examples to execute during this demo

Hi,
I'm looking for instructions on how to query Neptune using gremlin and display some things like "if you boughts this, you'd also want to look at that"
Can you share some examples that can be demoed using this application?

Move Neptune IAM role config to native CloudFormation

Is your feature request related to a problem? Please describe.
Refactor Neptune IAM role configuration to support native CloudFormation. This was originally implemented using a custom resource as applying an IAM role via CFN was not supported at the time.

Current implementation:

bookstoreNeptuneIAMAttach:

Latest support for IAM Role Attach with Neptune:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-neptune-dbcluster-dbclusterrole.html

"Mirror" s3 buckets to an organization bounded accounts

Hi There,
Our AWS accounts are a part of AWS Organizations.
We have some SCP in place that prevent access to AWS resources that do not belong to our organization.
Is there a way to copy the data to a local s3 bucket so we don't need to load data from external buckets ?
Thank you!

CodeBuild Fails COMMAND_EXECUTION_ERROR Message: Error while executing command: npm run build. Reason: exit status 1

Project create CodePipeline project. CodeBuild Fails with the following error...

Creating an optimized production build...

146 | Failed to compile.
147 |  
148 | /codebuild/output/src062423328/src/node_modules/@types/babel__traverse/index.d.ts
149 | TypeScript error in /codebuild/output/src062423328/src/node_modules/@types/babel__traverse/index.d.ts(68,50):
150 | ']' expected. TS1005
151 |  
152 | 66 | }
153 | 67 |
154 | > 68 | export type ArrayKeys = keyof { [P in keyof T as T[P] extends any[] ? P : never]: P };
155 | | ^
156 | 69 |
157 | 70 | export class Scope {
158 | 71 | constructor(path: NodePath, parentScope?: Scope);
159 |  
160 |  
161 | npm ERR! code ELIFECYCLE
162 | npm ERR! errno 1
163 | npm ERR! [email protected] build: react-scripts build
164 | npm ERR! Exit status 1
165 | npm ERR!
166 | npm ERR! Failed at the [email protected] build script.
167 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
168 |  
169 | npm ERR! A complete log of this run can be found in:
170 | npm ERR! /root/.npm/_logs/2023-01-12T21_39_57_365Z-debug.log
171 |  
172 | [Container] 2023/01/12 21:39:57 Command did not exit successfully npm run build exit status 1
173 | [Container] 2023/01/12 21:39:57 Phase complete: BUILD State: FAILED
174 | [Container] 2023/01/12 21:39:57 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm run build. Reason: exit status 1

image

image

S3 bucket not showing in parameters

Hi Team,

if you look at the read me file where it says regarding Deploying the cloudformation stack it says launch stack in us-east-1 and then in step 3 when going cloud formation wizard steps you have mentioned as Name your s3 bucket , but when i ran this template it was not asked any s3 bucket name , it seems they have changed the template

can you please update the readme file accordingly ? Adding the screenshots of both Readme and Parameters section in my cloudformation stack after I deployed this

Please let me know if you need any additional details.


Screenshot 2022-11-22 at 3 21 27 PM
Screenshot 2022-11-22 at 5 34 25 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.