Skip to content

lostcodingsomewhere/kotlin-serverless-v2

Repository files navigation

kotlin-serverless (API)

Overview

This framework is to be used to generate kotlin serverless based API's To add new API's:

  • Update serverless.yml
  • Update routes.yml
  • Add the appropriate service and unit test
  • Add the appropriate controller
  • Add the appropriate integration test

Tech stack:

  • Serverless, Kotlin, jUnit, exposed (mysql, auroraserverless), circleci, bugsnag

Install

NOTE: Make sure you're using Java 8 (v1.8.*)

  1. Install it using npm:
git clone git@github.com:lostcodingsomewhere/kotlin-serverless-v2.git
cd kotlin-serverless-v2
npm install serverless -g
npm init -f
npm install
  1. Create your project in serverless.com

  2. To configure your AWS credentials execute serverless config credentials --provider aws --key EXAMPLE --secret EXAMPLEKEY

  3. mvn clean install

  4. ./start.sh local

Deploying

  1. Create AWS Serverless Aurora RDS DB
    • Follow [Step 1, Step 2]
    • Note: Aurora serverless DBs can only be accessed from within the VPC, thus you cannot access it from your local server even if you change the inbound capabilities
    • Must access via EC2, Lambda Functions, or Cloud9IDE. EC2 route is described as follows.
  2. Create EC2 Instance to Access RDS DB
    • Note: Use same VPC/Security Group as the RDS DB
  3. Update Security group to have access between ec2 and rds
    • Follow [Step 4] but note below:
    • Edit inbound to add SSH from all and MYSQL/Aurora from all
  4. Add api database to the newly created db
    • Connect to the ec2 instance
    • ssh -i <path to pem file> ec2-user@<ec2 public url>
    • Update yum
    • sudo yum update
    • Install mysql if it doesn’t exist (check by using mysql command)
    • sudo yum install mysql
    • mysql -h <aurora db cluster url> -P 3306 -u <dbusername> -p
    • Create database lostcoders if it doesn’t exist
  5. Update serverless.yml
    • Vpc:, securityGroupIds, subnetIds
    • Environment: database_url, database_driver, database_user, database_password
    • For local env use after you have created a mysql database and added a lostcoders db:
      • database_url: jdbc:mysql://localhost:3306/api
      • database_driver: com.mysql.jdbc.Driver
      • database_user: root
      • database_password:
    • For production env use creds from above aws instances
  6. Setup env vars in serverless.yml and also add to AWS SMPS (ex: ${ssm:/lostcoders/production/database/user})
  7. Install serverless
  8. Setup AWS Creds for Serverless Framework
  9. Create project in https://dashboard.serverless.com if it doesn’t already exist
  10. To deploy ./start.sh
    ./start.sh local
    ./start.sh production

CI/CD

  • Using circleci you can setup continuous integration and deployment. Look at /.circleci/config.yml
  • Current configuration depends on the following:
    • all new pull requests will auto build and test
    • all pushes to master branch will deploy to development env
    • all pushes to production branch will deploy to production env
    • after any deployment, postman tests will get triggered

Contributing

  • Feel free to create pull requests in your own branch, include descriptions and tests.

Contributors

Contributions by:

Author

Arya Soltanieh

About

Kotlin Serverless Framework to create robust API's

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published