GithubHelp home page GithubHelp logo

tengoal / serverless-webapp-mono-repo-ci-cd-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/serverless-webapp-mono-repo-ci-cd-java

0.0 0.0 0.0 510 KB

Use AWS Serverless stack written in JAVA to build a full blown web application with both backend and frontend hosted inside a same mono repo.

License: MIT No Attribution

Java 58.42% Python 10.61% HTML 1.90% SCSS 0.73% TypeScript 27.79% CSS 0.54%

serverless-webapp-mono-repo-ci-cd-java's Introduction

serverless-webapp-ci-cd-java

Status: Work-in-progress. Please create issues or pull requests if you have ideas for improvement.

❤️ Backend is powered by aws-lambda-powertools-java and aws-lambda-powertools-python

Use AWS Serverless stack to build a full fledged web application with both backend and frontend hosted inside a same mono repo.

Backend CI/CD pipeline and backend infrastructure is written using SAM. Frontend CI/CD pipeline and infrastructure is written using CDK Java.

Application builds a React static web app, which talks to bunch of APIs hosted via API gateway and talking to lambda functions, S3 and dynamoDB as backends. Feature of web application itself is simple. Since that is not the main purpose here. User can basically upload an image with a metadata. Then if user want, they can try uploading another image from another flow, and try to find face in it. If its found in Dynamo DB, then we return the metadata.

Architecture diagram for the application

Architecture Diagram

Pre requisite

Make sure you have aws cli installed and configured with an aws account you want to use.

Creating backend with Full CI/CD pipeline

Note: If you wish to provision backend without CI/CD, refer instructions here

Assuming your region is eu-west-1, run below commands. Replace region value with your workload region.

  • Create backend CI/CD pipelines for deploying backend resource via cloudformation. You can either choose to deploy backend in python or in java. Both are deployed via SAM.
Java Backend

❤️ Backend is powered by aws-lambda-powertools-java

    aws cloudformation create-stack --stack-name serverless-web-application-java-backend-pipeline --template-body file://java-app-backend/serverless-pipeline.yaml --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM --region eu-west-1
  • Trigger Code build for deploying java backend resources via pipeline. It will use SAM to deploy serverless backend stack.
    aws codebuild start-build --project-name WebAppJavaBackendPipelineDetector --region eu-west-1
Python Backend

❤️ Backend is powered by aws-lambda-powertools-python

    aws cloudformation create-stack --stack-name serverless-web-application-python-backend-pipeline --template-body file://python-app-backend/serverless-pipeline.yaml --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM --region eu-west-1
  • Trigger Code build for deploying python backend resources via pipeline. It will use SAM to deploy serverless backend stack.
    aws codebuild start-build --project-name WebAppPythonBackendPipelineDetector --region eu-west-1
  • After this step, codepipeline should take care of deploying your backend resources. If you choose to deploy with manual approval step, Navigate to pipeline and approve to deploy the stack.

Creating frontend with full CI/CD pipeline

Note: If you wish to provision frontend without CI/CD, refer instructions here

Assuming your region is eu-west-1, run below commands. Replace region value with your workload region.

  • Update backend endpoints in GlobalConstants. Backend endpoints can be found by navigating to API gateway console

  • Revisit cdk.json for configurtion of frontend stack. You might want to update approval_emails, cert_domain. If you don't want to host on a custom domain, leave cert_domain as empty string. Leaving approval_emails as empty won't create any approval stage.

  • Create frontend CI/CD pipelines for deploying frontend resource via cdk.

    cd frontend-infrastructure/
    maven clean install
    cdk synth serverless-web-application-frontend-pipeline --region eu-west-1
    cdk bootstrap
    cdk deploy serverless-web-application-frontend-pipeline --region eu-west-1 --require-approval never
  • Trigger Code build for deploying backend resources via pipeline. It will use SAM to deploy serverless backend stack.
    aws codebuild start-build --project-name WebApplicationFrontEndPipelineDetector --region eu-west-1
  • If you are using custom domain, make sure to register created named servers on Route53 hosted zone with your domain provider.

  • 1st deployment of frontend will take some time since its need to initialise cloudfront distribution etc.

  • After this step, codepipeline should take care of deploying your frontend resources. If you choose to deploy with manual approval step, Navigate to pipeline and approve to deploy the stack.

Creating backend without Full CI/CD pipeline(Manually)

Java Backend
  cd java-app-backend/
  sam build
  • Run below command and pick default options.
  sam deploy --guided --stack-name serverless-web-application-java-backend --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM
Python Backend
  cd python-app-backend/
  sam build
  • Run below command and pick default options.
  sam deploy --guided --stack-name serverless-web-application-python-backend --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM

Creating frontend without Full CI/CD pipeline(Manually)

  • After one of the backend is created successfully, update backend endpoints in GlobalConstants. Backend endpoints can be found by navigating to API gateway console

  • Revisit cdk.json for configurtion of frontend stack. cert_domain. If you don't want to host on a custom domain, leave cert_domain as empty string.

  • Build frontend code

  cd frontend/
  yarn install
 
  yarn build
  • Build frontend infrastructure
  cd ../frontend-infrastructure/
  mvn clean install
  cdk synthesize serverless-web-application-frontend
  cdk deploy serverless-web-application-frontend
  • If you are using custom domain, make sure to register created named servers on Route53 hosted zone with your domain provider.

Cleanup resources

Run below commands as applicable in order.

Java Backend
    aws cloudformation delete-stack --stack-name serverless-web-application-java-backend --region eu-west-1
Python Backend
    aws cloudformation delete-stack --stack-name serverless-web-application-python-backend --region eu-west-1
  • Clean frontend
    aws cloudformation delete-stack --stack-name serverless-web-application-frontend --region eu-west-1
  • Clean up pipelines
Java Backend pipeline
    aws cloudformation delete-stack --stack-name serverless-web-application-java-backend-pipeline --region eu-west-1
Python Backend pipeline
    aws cloudformation delete-stack --stack-name serverless-web-application-python-backend-pipeline --region eu-west-1
Frontend pipeline
    aws cloudformation delete-stack --stack-name serverless-web-application-frontend-pipeline --region eu-west-1

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

serverless-webapp-mono-repo-ci-cd-java's People

Contributors

amazon-auto avatar dependabot[bot] avatar pankajagrawal16 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.