Giter VIP home page Giter VIP logo

ideal-octo-waffle's Introduction

Ideal Octo Waffle

Running the project

Authenticate

Export an authenticated profile

export AWS_PROFILE=<your_profile>

Clone the project

git clone [email protected]:andou/ideal-octo-waffle.git

Install dependencies

yarn && yarn --cwd ./logic/products && yarn --cwd ./logic/import

Choose an environment

Export the NODE_ENV variable with the environment of your choose, e.g. dev

export NODE_ENV=dev

For sake of simplicity, let's stick with the dev convention from now on, ok?

Create a conf file for this environment, config/dev.yaml

env: dev
account_number: "specify-the-account-number"
region: specify-the-region

Bootstrap CDK

cdk bootstrap

Deploy the stack

cdk deploy --outputs-file ./cdk-outputs.json

Retrieve the S3 bucket where to upload files

cat cdk-outputs.json | jq -r '."ideal-octo-waffle-dev-main-stack".s3UrlForObject'

Upload some data

NOTE Change dev in the command below accordingly to the environment you have choose,

aws s3 cp sample/products_10.csv $(cat cdk-outputs.json | jq -r '."ideal-octo-waffle-dev-main-stack".s3UrlForObject')/products/products_10.csv
aws s3 cp sample/stocks_10.csv $(cat cdk-outputs.json | jq -r '."ideal-octo-waffle-dev-main-stack".s3UrlForObject')/stock/stocks_10.csv

Make some API call

First, retrieve the api key

NOTE Change dev in the command below accordingly to the environment you have choose,

aws apigateway get-api-key --api-key $(cat cdk-outputs.json | jq -r '."ideal-octo-waffle-dev-main-stack".apiKeyId') --include-value | jq -r '.value'

and the API ID

cat cdk-outputs.json | jq -r '."ideal-octo-waffle-dev-main-stack".restApiId'

then you can fetch a single product

curl --header "x-api-key: <your_key>" https://<restApiId>.execute-api.eu-west-1.amazonaws.com/dev/products/09-8086714 | jq

{
  "price": "42.57",
  "name": "Radish",
  "sku": "09-8086714",
  "quantity": "1234"
}

or all the products

curl --header "x-api-key: <your_key>" https://<restApiId>.execute-api.eu-west-1.amazonaws.com/dev/products/ | jq
{
  "products": [
    {
      "price": "2.5",
      "name": "Water Chestnut - Canned",
      "sku": "55-4451992",
      "quantity": "578"
    },
    {
      "price": "8.51",
      "name": "Cheese - CiccioPasticcio",
      "sku": "65-2543216",
      "quantity": "399"
    },
    {
      "price": "56.29",
      "name": "Energy - Boo - Koo",
      "sku": "44-3995800",
      "quantity": "799"
    }
  ]
}

Clean everything up

cdk destroy

Improvements

Get all products

The API to retrieve all products performs a scan of the whole table does not use pagination. The API should be modified to take pagination into account and reduce large amount of data to be transferred at each call.

Sync file read

The data import performs a synchronous reading of the CSV file uploaded to S3 before parsing it. On very large CSV files, this could be a problem. It would be more appropriate to read from a buffer and parse accordingly.

Sync batch write

Once the file is parsed, the data is inserted into DynamoDB by the same Lambda through a batch write. It would be better if the records were sent to an SQS queue to be dequeued by another Lambda, which would then perform the writing to DynamoDB.

Code cleaning and test

The code probably needs a cleanup and definitely needs unit tests.

Deployment pipeline

I haven't had the time to set up a pipeline for deploying the solution; you must rely on your own CLI, at the moment.

ideal-octo-waffle's People

Contributors

andou avatar

Watchers

 avatar

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.