Giter Site home page Giter Site logo

aws-cdk-lambda-rest-api's Introduction

Serverless REST API using AWS Cloud Development Kit (CDK) and Java

The cdk.json file tells the CDK Toolkit how to execute your app.

It is a Maven based project, so you can open this project with any Maven compatible Java IDE to build and run tests.

Useful commands

  • mvn package compile and run tests
  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

AWS Services

  1. AWS REST API Gateway (not the HTTP API Gateway)
  2. AWS Lambda
  3. AWS Cognito User Pool
  4. AWS DynamoDB

Project Status

Feature Status
CRUD on models Completed
Endpoint secured via Cognito Completed
Display results in JSON API Completed
Deployed on AWS Completed

Notes on the API Gateway

The API gateway defined in this CDK project is using AWS REST API (not AWS HTTP API). Differences on these API Gateways are available here: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html

Securing the API Gateway

  1. Endpoint is secured using AWS Cognito User Pool
  2. By default, ID token is used as part of Authentication bearer token.
  3. Access token can be used however it requires a custom client scope set in Cognito

For Testing Purpose

  1. Client Credentials flow is set up to easily retrieve token
  2. This requires custom client scope hence, access token is used

Reference: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html

Reflection

Cloud computing is ubiquitous, and AWS is one of the leaders in this space. Some firms are using serverless approach to cut out complexity in handling their technology pipeline. As a developer, it is important to keep myself updated with what's happening in the space.

Developing a serverless application is a completely different paradigm. One has to think in terms of services when it comes to application design. Building it out on the cloud also requires a certain level of knowledge of the services these cloud computing providers have.

These lambda functions were written in vanilla Java. Some of these functions are tedious and verbose. As a Spring framework developer, I appreciate what the Spring framework does by creating common classes or simplifying common patterns through the use of annotations.

The other challenge faced was that Java is not a popular language when it comes to lambda and AWS CDK. Finding resources or guides was challenging but the AWS guides were well-written and sufficient.

Reason for choosing AWS amongst other cloud providers was to aid my learning for my AWS certifications. The use of CDK is pretty awesome for lack of a better word. It is similar to Terraform or other Code as a Infrastructure product. I created an entirely serverless REST API with authentication using lines of code. CDK is based on AWS Cloudformation.

Tools used

  1. Postman - to test the endpoints
  2. Intellij IDE

aws-cdk-lambda-rest-api's People

Contributors

649000 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.