├── .gitignore ├── .jetskeep ├── .rspec ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── Procfile ├── README.md ├── Rakefile ├── app ├── controllers │ ├── application_controller.rb │ └── posts_controller.rb ├── helpers │ └── application_helper.rb ├── jobs │ └── application_job.rb └── models │ ├── application_item.rb │ ├── application_record.rb │ └── post.rb ├── config.ru ├── config ├── application.rb ├── database.yml ├── dynamodb.yml ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb └── routes.rb ├── db ├── .gitkeep ├── migrate │ └── 20190503112120_create_posts.rb ├── schema.rb └── seeds.rb ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico └── index.html └── spec ├── controllers └── posts_controller_spec.rb ├── fixtures └── payloads │ ├── posts-index.json │ └── posts-show.json └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | .byebug_history 4 | .DS_Store 5 | .env* 6 | /node_modules 7 | /public/packs 8 | /public/packs-test 9 | bundled 10 | coverage 11 | pkg 12 | tmp 13 | -------------------------------------------------------------------------------- /.jetskeep: -------------------------------------------------------------------------------- 1 | pack 2 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format documentation 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.5.1@serverless-ruby-simple-crud 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "jets" 4 | 5 | 6 | # Include mysql2 gem if you are using ActiveRecord, remove if you are not 7 | gem "mysql2", "~> 0.5.2" 8 | 9 | gem "dynomite" 10 | 11 | group :development, :test do 12 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 13 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 14 | gem 'shotgun' 15 | gem 'rack' 16 | end 17 | 18 | group :test do 19 | gem 'rspec' # rspec test group only or we get the "irb: warn: can't alias context from irb_context warning" when starting jets console 20 | gem 'launchy' 21 | gem 'capybara' 22 | end 23 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (6.0.2.1) 5 | actionpack (= 6.0.2.1) 6 | actionview (= 6.0.2.1) 7 | activejob (= 6.0.2.1) 8 | mail (~> 2.5, >= 2.5.4) 9 | rails-dom-testing (~> 2.0) 10 | actionpack (6.0.2.1) 11 | actionview (= 6.0.2.1) 12 | activesupport (= 6.0.2.1) 13 | rack (~> 2.0, >= 2.0.8) 14 | rack-test (>= 0.6.3) 15 | rails-dom-testing (~> 2.0) 16 | rails-html-sanitizer (~> 1.0, >= 1.2.0) 17 | actionview (6.0.2.1) 18 | activesupport (= 6.0.2.1) 19 | builder (~> 3.1) 20 | erubi (~> 1.4) 21 | rails-dom-testing (~> 2.0) 22 | rails-html-sanitizer (~> 1.1, >= 1.2.0) 23 | activejob (6.0.2.1) 24 | activesupport (= 6.0.2.1) 25 | globalid (>= 0.3.6) 26 | activemodel (6.0.2.1) 27 | activesupport (= 6.0.2.1) 28 | activerecord (6.0.2.1) 29 | activemodel (= 6.0.2.1) 30 | activesupport (= 6.0.2.1) 31 | activesupport (6.0.2.1) 32 | concurrent-ruby (~> 1.0, >= 1.0.2) 33 | i18n (>= 0.7, < 2) 34 | minitest (~> 5.1) 35 | tzinfo (~> 1.1) 36 | zeitwerk (~> 2.2) 37 | addressable (2.7.0) 38 | public_suffix (>= 2.0.2, < 5.0) 39 | aws-eventstream (1.0.3) 40 | aws-mfa-secure (0.4.0) 41 | activesupport 42 | aws-sdk-core 43 | aws_config 44 | memoist 45 | rainbow 46 | thor 47 | zeitwerk 48 | aws-partitions (1.262.0) 49 | aws-sdk-apigateway (1.36.0) 50 | aws-sdk-core (~> 3, >= 3.71.0) 51 | aws-sigv4 (~> 1.1) 52 | aws-sdk-cloudformation (1.29.0) 53 | aws-sdk-core (~> 3, >= 3.71.0) 54 | aws-sigv4 (~> 1.1) 55 | aws-sdk-cloudwatchlogs (1.27.0) 56 | aws-sdk-core (~> 3, >= 3.71.0) 57 | aws-sigv4 (~> 1.1) 58 | aws-sdk-core (3.86.0) 59 | aws-eventstream (~> 1.0, >= 1.0.2) 60 | aws-partitions (~> 1, >= 1.239.0) 61 | aws-sigv4 (~> 1.1) 62 | jmespath (~> 1.0) 63 | aws-sdk-dynamodb (1.41.0) 64 | aws-sdk-core (~> 3, >= 3.71.0) 65 | aws-sigv4 (~> 1.1) 66 | aws-sdk-kinesis (1.20.0) 67 | aws-sdk-core (~> 3, >= 3.71.0) 68 | aws-sigv4 (~> 1.1) 69 | aws-sdk-kms (1.27.0) 70 | aws-sdk-core (~> 3, >= 3.71.0) 71 | aws-sigv4 (~> 1.1) 72 | aws-sdk-lambda (1.34.0) 73 | aws-sdk-core (~> 3, >= 3.71.0) 74 | aws-sigv4 (~> 1.1) 75 | aws-sdk-s3 (1.60.1) 76 | aws-sdk-core (~> 3, >= 3.83.0) 77 | aws-sdk-kms (~> 1) 78 | aws-sigv4 (~> 1.1) 79 | aws-sdk-sns (1.21.0) 80 | aws-sdk-core (~> 3, >= 3.71.0) 81 | aws-sigv4 (~> 1.1) 82 | aws-sdk-sqs (1.23.1) 83 | aws-sdk-core (~> 3, >= 3.71.0) 84 | aws-sigv4 (~> 1.1) 85 | aws-sdk-ssm (1.69.0) 86 | aws-sdk-core (~> 3, >= 3.71.0) 87 | aws-sigv4 (~> 1.1) 88 | aws-sigv4 (1.1.0) 89 | aws-eventstream (~> 1.0, >= 1.0.2) 90 | aws_config (0.1.0) 91 | builder (3.2.4) 92 | byebug (11.0.1) 93 | capybara (3.30.0) 94 | addressable 95 | mini_mime (>= 0.1.3) 96 | nokogiri (~> 1.8) 97 | rack (>= 1.6.0) 98 | rack-test (>= 0.6.3) 99 | regexp_parser (~> 1.5) 100 | xpath (~> 3.2) 101 | cfn_camelizer (0.4.9) 102 | activesupport 103 | memoist 104 | rainbow 105 | cfnresponse (0.4.0) 106 | concurrent-ruby (1.1.5) 107 | crass (1.0.5) 108 | diff-lcs (1.3) 109 | dotenv (2.7.5) 110 | dynomite (1.2.5) 111 | activesupport 112 | aws-sdk-dynamodb 113 | rainbow 114 | erubi (1.9.0) 115 | gems (1.2.0) 116 | globalid (0.4.2) 117 | activesupport (>= 4.2.0) 118 | hashie (4.0.0) 119 | i18n (1.7.1) 120 | concurrent-ruby (~> 1.0) 121 | jets (2.3.11) 122 | actionmailer (~> 6.0.0) 123 | actionpack (~> 6.0.0) 124 | actionview (~> 6.0.0) 125 | activerecord (~> 6.0.0) 126 | activesupport (~> 6.0.0) 127 | aws-mfa-secure (~> 0.4.0) 128 | aws-sdk-apigateway 129 | aws-sdk-cloudformation 130 | aws-sdk-cloudwatchlogs 131 | aws-sdk-dynamodb 132 | aws-sdk-kinesis 133 | aws-sdk-lambda 134 | aws-sdk-s3 135 | aws-sdk-sns 136 | aws-sdk-sqs 137 | aws-sdk-ssm 138 | cfn_camelizer (~> 0.4.6) 139 | cfnresponse 140 | dotenv 141 | gems 142 | hashie 143 | jets-gems 144 | jets-html-sanitizer 145 | json 146 | kramdown 147 | memoist 148 | mimemagic 149 | rack 150 | railties (~> 6.0.0) 151 | rainbow 152 | recursive-open-struct 153 | shotgun 154 | text-table 155 | thor 156 | zeitwerk 157 | jets-gems (0.2.0) 158 | gems 159 | jets-html-sanitizer (1.0.4) 160 | loofah (~> 2.2, >= 2.2.2) 161 | jmespath (1.4.0) 162 | json (2.3.0) 163 | kramdown (2.1.0) 164 | launchy (2.4.3) 165 | addressable (~> 2.3) 166 | loofah (2.4.0) 167 | crass (~> 1.0.2) 168 | nokogiri (>= 1.5.9) 169 | mail (2.7.1) 170 | mini_mime (>= 0.1.1) 171 | memoist (0.16.2) 172 | method_source (0.9.2) 173 | mimemagic (0.3.3) 174 | mini_mime (1.0.2) 175 | mini_portile2 (2.4.0) 176 | minitest (5.13.0) 177 | mysql2 (0.5.3) 178 | nokogiri (1.10.7) 179 | mini_portile2 (~> 2.4.0) 180 | public_suffix (4.0.3) 181 | rack (2.0.8) 182 | rack-test (1.1.0) 183 | rack (>= 1.0, < 3) 184 | rails-dom-testing (2.0.3) 185 | activesupport (>= 4.2.0) 186 | nokogiri (>= 1.6) 187 | rails-html-sanitizer (1.3.0) 188 | loofah (~> 2.3) 189 | railties (6.0.2.1) 190 | actionpack (= 6.0.2.1) 191 | activesupport (= 6.0.2.1) 192 | method_source 193 | rake (>= 0.8.7) 194 | thor (>= 0.20.3, < 2.0) 195 | rainbow (3.0.0) 196 | rake (13.0.1) 197 | recursive-open-struct (1.1.0) 198 | regexp_parser (1.6.0) 199 | rspec (3.9.0) 200 | rspec-core (~> 3.9.0) 201 | rspec-expectations (~> 3.9.0) 202 | rspec-mocks (~> 3.9.0) 203 | rspec-core (3.9.1) 204 | rspec-support (~> 3.9.1) 205 | rspec-expectations (3.9.0) 206 | diff-lcs (>= 1.2.0, < 2.0) 207 | rspec-support (~> 3.9.0) 208 | rspec-mocks (3.9.1) 209 | diff-lcs (>= 1.2.0, < 2.0) 210 | rspec-support (~> 3.9.0) 211 | rspec-support (3.9.2) 212 | shotgun (0.9.2) 213 | rack (>= 1.0) 214 | text-table (1.2.4) 215 | thor (1.0.1) 216 | thread_safe (0.3.6) 217 | tzinfo (1.2.6) 218 | thread_safe (~> 0.1) 219 | xpath (3.2.0) 220 | nokogiri (~> 1.8) 221 | zeitwerk (2.2.2) 222 | 223 | PLATFORMS 224 | ruby 225 | 226 | DEPENDENCIES 227 | byebug 228 | capybara 229 | dynomite 230 | jets 231 | launchy 232 | mysql2 (~> 0.5.2) 233 | rack 234 | rspec 235 | shotgun 236 | 237 | BUNDLED WITH 238 | 2.1.4 239 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | local: dynamodb-local # port 8000 2 | admin: env AWS_ACCESS_KEY_ID=$DYNAMODB_ADMIN_AWS_ACCESS_KEY_ID PORT=8001 dynamodb-admin # port 8001 3 | # web: jets server # port 8888 4 | 5 | # Using Procfile to just start local dynamodb services for now. 6 | # To start jets server for now use: 7 | # jets server 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Serverless Rest APIs 2 | This is a simple serverless application build over Jets framework of the ruby. The application illustrates how we can create Serverless CRUD APIs using Jets framework. 3 | ## Requirements 4 | * RVM 5 | * Ruby(2.5.1) 6 | * AWS CLI 7 | 8 | ## Setup 9 | 10 | ### Step 1 - Install RVM 11 | * Follow the steps given here: https://rvm.io/rvm/install, to install RVM in your machines 12 | 13 | ### Step 2 - Install Ruby 14 | To install ruby(2.5.1) in your machine, run following command 15 | ```sh 16 | $ rvm install ruby-2.5.1 17 | ``` 18 | ### Step 3 - Install & Configure AWS 19 | ```sh 20 | $ sudo apt install awscli 21 | $ aws configure 22 | ``` 23 | 24 | ### Step 4 - Take clone of the repository 25 | 26 | ```ruby_on_rails 27 | $ git clone https://github.com/SystangoTechnologies/serverless-ruby-simple-crud.git 28 | $ cd serverless-ruby-simple-crud 29 | $ bundle install 30 | ``` 31 | 32 | ### Step 5 - Setup Database 33 | 34 | ```ruby_on_rails 35 | $ jets db:create db:migrate db:seed 36 | ``` 37 | ### Step 6 - Run Application 38 | 39 | To start your the jets server locally, you need to run 40 | 41 | ```ruby_on_rails 42 | $ jets s 43 | ``` 44 | Your Service must be running on http://localhost:8888 45 | 46 | You can access the all the posts created using seed file on http://localhost:8888/posts 47 | 48 | ## Deployment 49 | Before we deploy, we need to create a database that AWS Lambda will have access to. 50 | We’ll also have to create and migrate the RDS database. 51 | ```ruby_on_rails 52 | $ vim .env.development.remote # configure a remote RDS DB 53 | $ JETS_ENV_REMOTE=1 jets db:create db:migrate 54 | ``` 55 | Once that is completed, let’s deploy our application to AWS Lambda. 56 | 57 | ```ruby_on_rails 58 | $ jets deploy 59 | ``` 60 | 61 | Once the application is deployed you will get the API endpoint using which you can access APIs. 62 | 63 | ## Security 64 | 65 | Once API gateway is created, you must setup Usage plan along with their API Keys form API gateway console. For this, you can follow the [official doc](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-setup-api-key-with-console.html) for the same given by AWS. 66 | 67 | If you want a custom authorization instead of this, just comment out the **before_filter:authorize** line in application.rb to make custom authorization work. 68 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'jets' 2 | Jets.load_tasks 3 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < Jets::Controller::Base 2 | include ApplicationHelper 3 | # before_action :authorize 4 | 5 | private 6 | def authorize 7 | authorization_key = get_authorization_key(request.headers['authorization']) 8 | if authorization_key != "#{ENV['API_CLIENT_ID']}:#{ENV['API_CLIENT_SECRET']}" 9 | render json: {message: "Unauthorized"}, status: 401 10 | end 11 | end 12 | end -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class PostsController < ApplicationController 2 | before_action :set_post, only: [:show, :update, :delete] 3 | 4 | # GET /posts 5 | def index 6 | @posts = Post.all 7 | render json: @posts, status: 200 8 | end 9 | 10 | # GET /posts/1 11 | def show 12 | render json: @post, status: 200 13 | end 14 | 15 | # POST /posts 16 | def create 17 | @post = Post.new(post_params) 18 | if @post.save 19 | set_header("Location", ENV['API_ENDPOINT']+"/posts/#{@post.id}") 20 | render json: {id: @post.id}, status: 201 21 | else 22 | render json: {mesasge: @post.errors.full_messages.join(", ")}, status: 422 23 | end 24 | end 25 | 26 | # PATCH/PUT /posts/1 27 | def update 28 | if @post.update(post_params) 29 | render json: {}, status: 204 30 | else 31 | render json: {mesasge: @post.errors.full_messages.join(", ")}, status: 422 32 | end 33 | end 34 | 35 | # DELETE /posts/1 36 | def delete 37 | @post.destroy 38 | render json: {}, status: 204 39 | end 40 | 41 | private 42 | 43 | # Use callbacks to share common setup or constraints between actions. 44 | def set_post 45 | @post = Post.find_by_id(params[:id]) 46 | render json: {}, status: 404 if @post.nil? 47 | end 48 | 49 | # Only allow a trusted parameter "white list" through. 50 | def post_params 51 | params.fetch(:post, {}).permit(:title) 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | require 'base64' 2 | 3 | module ApplicationHelper 4 | def get_authorization_key(authorization) 5 | Base64.decode64(authorization) rescue false 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < Jets::Job::Base 2 | # Adjust to increase the default timeout for all Job classes 3 | class_timeout 60 4 | end 5 | -------------------------------------------------------------------------------- /app/models/application_item.rb: -------------------------------------------------------------------------------- 1 | class ApplicationItem < Dynomite::Item 2 | end 3 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ApplicationRecord 2 | validates_presence_of :title 3 | end 4 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require "jets" 4 | Jets.boot 5 | run Jets.application 6 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | Jets.application.configure do 2 | config.project_name = 'serverless-ruby-simple-crud' 3 | config.mode = 'api' 4 | 5 | # config.prewarm.enable = true # default is true 6 | # config.prewarm.rate = '30 minutes' # default is '30 minutes' 7 | # config.prewarm.concurrency = 2 # default is 2 8 | # config.prewarm.public_ratio = 3 # default is 3 9 | 10 | # config.env_extra = 2 # can also set this with JETS_ENV_EXTRA 11 | # config.extra_autoload_paths = [] 12 | 13 | # config.asset_base_url = 'https://cloudfront.domain.com/assets' # example 14 | 15 | config.cors = true # for '*'' # defaults to false 16 | config.cors_preflight = { 17 | "access-control-allow-methods" => "DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT", 18 | "access-control-allow-headers" => "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent", 19 | } 20 | # config.cors = '*.mydomain.com' # for specific domain 21 | 22 | # config.function.timeout = 30 # defaults to 30 23 | # config.function.role = "arn:aws:iam::#{Jets.aws.account}:role/service-role/pre-created" 24 | # config.function.memory_size = 1536 25 | 26 | # config.api.endpoint_type = 'PRIVATE' # Default is 'EDGE' (https://docs.aws.amazon.com/apigateway/api-reference/link-relation/restapi-create/#endpointConfiguration) 27 | 28 | # config.function.environment = { 29 | # global_app_key1: "global_app_value1", 30 | # global_app_key2: "global_app_value2", 31 | # } 32 | # More examples: 33 | # config.function.dead_letter_queue = { target_arn: "arn" } 34 | # config.function.vpc_config = { 35 | # security_group_ids: [ "sg-1", "sg-2" ], 36 | # subnet_ids: [ "subnet-1", "subnet-2" ] 37 | # } 38 | # The config.function settings to the CloudFormation Lambda Function properties. 39 | # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html 40 | # Underscored format can be used for keys to make it look more ruby-ish. 41 | 42 | # Assets settings 43 | # The config.assets.folders are folders within the public folder that will be set 44 | # to public-read on s3 and served directly. IE: public/assets public/images public/packs 45 | # config.assets.folders = %w[assets images packs] 46 | # config.assets.max_age = 3600 # when to expire assets 47 | # config.assets.cache_control = nil # IE: "public, max-age=3600" # override max_age for more fine-grain control. 48 | # config.assets.base_url = nil # IE: https://cloudfront.com/my/base/path, defaults to the s3 bucket url 49 | # IE: https://s3-us-west-2.amazonaws.com/demo-dev-s3bucket-1inlzkvujq8zb 50 | 51 | # config.api.endpoint_type = 'PRIVATE' # Default is 'EDGE' https://amzn.to/2r0Iu2L 52 | # config.api.authorization_type = "AWS_IAM" # default is 'NONE' https://amzn.to/2qZ7zLh 53 | 54 | 55 | # config.domain.hosted_zone_name = "example.com" 56 | # us-west-2 REGIONAL endpoint 57 | # config.domain.cert_arn = "arn:aws:acm:us-west-2:112233445566:certificate/8d8919ce-a710-4050-976b-b33da991e123" 58 | # us-east-1 EDGE endpoint 59 | # config.domain.cert_arn = "arn:aws:acm:us-east-1:112233445566:certificate/d68472ba-04f8-45ba-b9db-14f839d57123" 60 | # config.domain.endpoint_type = "EDGE" 61 | 62 | # By default logger needs to log to $stderr for CloudWatch to receive Lambda messages, but for 63 | # local testing environment you may want to log these messages to 'test.log' file to keep your 64 | # testing suite output readable. 65 | # config.logger = Jets::Logger.new($strerr) 66 | end 67 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | adapter: mysql2 3 | encoding: utf8 4 | pool: <%= ENV["DB_POOL"] || 5 %> 5 | database: <%= ENV['DB_NAME'] || 'serverless-ruby-simple-apis_development' %> 6 | username: <%= ENV['DB_USER'] || 'root' %> 7 | password: <%= ENV['DB_PASS'] %> 8 | host: <%= ENV["DB_HOST"] %> 9 | url: <%= ENV['DATABASE_URL'] %> # takes higher precedence than other settings 10 | 11 | development: 12 | <<: *default 13 | database: <%= ENV['DB_NAME'] || 'serverless-ruby-simple-apis_development' %> 14 | 15 | test: 16 | <<: *default 17 | database: serverless-ruby-simple-apis_test 18 | 19 | production: 20 | <<: *default 21 | database: serverless-ruby-simple-apis_production 22 | url: <%= ENV['DATABASE_URL'] %> 23 | -------------------------------------------------------------------------------- /config/dynamodb.yml: -------------------------------------------------------------------------------- 1 | # Jets::Config.project_namespace is special value results in using the project namespace. Example : 2 | # table_namespace: <%= Jets.config.project_namespace %> 3 | # This is the default value. 4 | 5 | development: 6 | table_namespace: <%= Jets.config.table_namespace %> 7 | # More examples: 8 | # table_namespace: demo-dev 9 | 10 | endpoint: http://localhost:8000 # comment out if want to test with real dynamodb 11 | # on AWS. You can also set the DYNAMODB_ENDPOINT environment variable. 12 | # You can also are actually deploying a development environment is to 13 | # change bin/server and export DYNAMODB_ENDPOINT=http://localhost:8000 at the top 14 | # there. 15 | 16 | test: 17 | # table_namespace: proj # do not include the env 18 | endpoint: http://localhost:8000 19 | table_namespace: <%= Jets.config.table_namespace %> 20 | 21 | production: 22 | table_namespace: <%= Jets.config.table_namespace %> 23 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Jets.application.configure do 2 | # Example: 3 | # config.function.memory_size = 1536 4 | 5 | # config.action_mailer.raise_delivery_errors = false 6 | # Docs: http://rubyonjets.com/docs/email-sending/ 7 | end 8 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Jets.application.configure do 2 | # Example: 3 | # config.function.memory_size = 2048 4 | 5 | # Ignore bad email addresses and do not raise email delivery errors. 6 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 7 | # Docs: http://rubyonjets.com/docs/email-sending/ 8 | # config.action_mailer.raise_delivery_errors = false 9 | end 10 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Jets.application.configure do 2 | # Tell Action Mailer not to deliver emails to the real world. 3 | # The :test delivery method accumulates sent emails in the 4 | # ActionMailer::Base.deliveries array. 5 | # Docs: http://rubyonjets.com/docs/email-sending/ 6 | config.action_mailer.delivery_method = :test 7 | end 8 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Jets.application.routes.draw do 2 | resources :posts 3 | root "jets/public#show" 4 | 5 | # The jets/public#show controller can serve static utf8 content out of the public folder. 6 | # Note, as part of the deploy process Jets uploads files in the public folder to s3 7 | # and serves them out of s3 directly. S3 is well suited to serve static assets. 8 | # More info here: http://rubyonjets.com/docs/assets-serving/ 9 | any "*catchall", to: "jets/public#show" 10 | end 11 | -------------------------------------------------------------------------------- /db/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SystangoTechnologies/serverless-ruby-simple-crud/7a04b473b78a6b6819136b82efa41aee752cd721/db/.gitkeep -------------------------------------------------------------------------------- /db/migrate/20190503112120_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration[5.2] 2 | def change 3 | create_table :posts do |t| 4 | t.string :title 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2019_05_03_112120) do 14 | 15 | create_table "posts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 16 | t.string "title" 17 | t.datetime "created_at", null: false 18 | t.datetime "updated_at", null: false 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | 3.times do |i| 2 | Post.create(title: "Title #{i+1}") 3 | end 4 | puts "Seeding data completed" -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |You may have mistyped the address or the page may have moved.
63 |If you are the application owner check the logs for more information.
65 |Maybe you tried to change something you didn't have access to.
63 |If you are the application owner check the logs for more information.
65 |If you are the application owner check the logs for more information.
64 |73 | To get started: 74 |
75 |
76 | $ jets generate scaffold Post title:string
77 | $ jets db:create db:migrate
78 | $ jets server
79 | $ open http://localhost:8888/posts
80 | $ jets help
81 |
More on info: rubyonjets.com
83 |Also check out the Jets CLI reference.
84 |
86 | Jets version: 1.8.9
87 | Ruby version: 2.5.3
88 |