Permalink
Browse files

Switch API Gateway from Terraform to Serverless Framwork.

  • Loading branch information...
ne-sachirou committed Aug 5, 2016
1 parent f94add8 commit 01051631f00651825164bdfa299f9ce9b760cf9b
View
@@ -1,9 +1,145 @@
*.tfplan
-.terraform
-# Created by https://www.gitignore.io/api/terraform
+
+# Created by https://www.gitignore.io/api/terraform,node,python
### Terraform ###
# Compiled files
*.tfstate
*.tfstate.backup
+
+# Module directory
+.terraform/
+
+
+### Node ###
+# Logs
+logs
+*.log
+npm-debug.log*
+
+# Runtime data
+pids
+*.pid
+*.seed
+*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# nyc test coverage
+.nyc_output
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directories
+node_modules
+jspm_packages
+
+# Optional npm cache directory
+.npm
+
+# Optional REPL history
+.node_repl_history
+
+
+### Python ###
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+.hypothesis/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# IPython Notebook
+.ipynb_checkpoints
+
+# pyenv
+.python-version
+
+# celery beat schedule file
+celerybeat-schedule
+
+# dotenv
+.env
+
+# virtualenv
+venv/
+ENV/
+
+# Spyder project settings
+.spyderproject
+
+# Rope project settings
+.ropeproject
View
@@ -1,2 +1,5 @@
+AllCops:
+ TargetRubyVersion: 2.3
+
Metrics/LineLength:
Max: 160
View
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
source 'https://rubygems.org'
gem 'rake'
View
@@ -7,7 +7,7 @@ GEM
powerpack (0.1.1)
rainbow (2.1.0)
rake (11.2.2)
- rubocop (0.41.2)
+ rubocop (0.42.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
View
@@ -1,15 +1,3 @@
c4se
==
c4se's infrastructure code.
-
-API Gatewayの更新手順
---
-1. LambdaのコードとAPI Gatewayの設定を書き換へる
-2. (Lambdaのコードを更新した場合は) `bundle exec rake build:aws_lambda`
-3. `bundle exec rake build:terraform` の後に `bundle exec rake deploy:terraform`
-4. (API Gatewayの設定を更新した場合は) `bundle exec rake deploy:aws_apigateway` でstagingの設定をデプロイする
-5. (Lambdaのコードを更新した場合は)
- - `bundle exec deploy:aws_lambda` で、表示されたVersionをメモする
- - 上でメモしたVersionを `prod_function_version` に設定する
- - `bundle exec rake build:terraform` の後に `bundle exec rake deploy:terraform`
-6. (API Gatewayの設定を更新した場合は) `bundle exec rake deploy:aws_apigateway` でproductionの設定をデプロイする
View
@@ -1,9 +1,12 @@
+# frozen_string_literal: true
require 'base64'
require 'digest'
require 'fileutils'
require 'json'
+require 'net/http'
require 'shellwords'
require 'tempfile'
+require 'uri'
aws_lambdas = {
'get_random' => 'crud_random',
@@ -78,7 +81,7 @@ namespace :deploy do
begin
Bundler.with_clean_env { sh 'terraform apply terraform.tfplan' }
ensure
- sh 'rm terraform.tfplan'
+ FileUtils.rm_f 'terraform.tfplan'
end
end
end
@@ -95,3 +98,24 @@ namespace :test do
end
end
end
+
+namespace :update do
+ desc 'Update rubygems.'
+ task(:gem) { sh 'bundle update' }
+
+ desc 'Update .gitignore'
+ task :gitignore do
+ gitignore = File.read '.gitignore', encoding: Encoding::UTF_8
+ url = %r{\n# Created by (https://www\.gitignore\.io/api/.+)$}.match(gitignore)&.send(:[], 1)&.chomp
+ next unless url
+ res = Net::HTTP.get URI(url)
+ gitignore = gitignore.sub %r{\n# Created by https://www\.gitignore\.io/api/.+}m, res
+ File.write '.gitignore', gitignore, encoding: Encoding::UTF_8
+ end
+
+ desc 'Update npm.'
+ task :npm do
+ sh 'node_modules/npm-check-updates/bin/ncu -u'
+ sh 'npm update'
+ end
+end
View
Binary file not shown.
@@ -1,46 +0,0 @@
-# coding=UTF-8
-"""API GET random."""
-from common import (
- logger,
- RandomRepo
-)
-import re
-import traceback
-
-
-class EventValidationException(Exception):
- """Fail to validate event."""
-
- def __str__(self):
- """To string."""
- return "400: %s" % self.message
-
-
-def validate_event(event):
- """Validate request params."""
- for key in ["id", "stage"]:
- if key not in event:
- raise EventValidationException("Event should have `%s`." % key)
- if not re.match(r"\A[0-9A-Za-z]+\Z", event["id"]):
- raise EventValidationException("`id` should match [0-9A-Za-z]+")
- if event["stage"] not in ["staging", "prod"]:
- raise EventValidationException("`stage` should be 'staging' or 'prod'.")
-
-
-def main(event, context):
- """Lambda handler."""
- try:
- logger.info(event)
- validate_event(event)
- repo = RandomRepo(event["stage"])
- item = repo.find(event["id"])
- return {
- "id": item.id,
- "code": item.code
- }
- except Exception as e:
- logger.error("%s\n%s" % (e, traceback.format_exc()))
- m = re.match(r"\A\d{3}: ", e.__str__())
- if (not m) or (m and m.group(0)[0:3] not in ["400", "500"]):
- e = Exception("500: %s" % e)
- raise e
@@ -1,47 +0,0 @@
-# coding=UTF-8
-"""API PUT random."""
-from common import (
- logger,
- RandomRepo
-)
-import re
-import traceback
-
-
-class EventValidationException(Exception):
- """Fail to validate event."""
-
- def __str__(self):
- """To string."""
- return "400: %s" % self.message
-
-
-def validate_event(event):
- """Validate request params."""
- for key in ["id", "stage"]:
- if key not in event:
- raise EventValidationException("Event should have `%s`." % key)
- if re.match(r"\A[0-9A-Za-z]+\Z", event["id"]) is None:
- raise EventValidationException("`id` should match [0-9A-Za-z]+")
- if event["stage"] not in ["staging", "prod"]:
- raise EventValidationException("`stage` should be 'staging' or 'prod'.")
-
-
-def main(event, context):
- """Lambda handler."""
- try:
- logger.info(event)
- validate_event(event)
- repo = RandomRepo(event["stage"])
- item = repo.find(event["id"])
- repo.gen_code(item)
- return {
- "id": item.id,
- "code": item.code
- }
- except Exception as e:
- logger.error("%s\n%s" % (e, traceback.format_exc()))
- m = re.match(r"\A\d{3}: ", e.__str__())
- if (not m) or (m and m.group(0)[0:3] not in ["400", "500"]):
- e = Exception("500: %s" % e)
- raise e
View
Binary file not shown.
@@ -1,8 +0,0 @@
-"""Dummy heartbeat endpoint."""
-
-
-def main(event, context):
- """Lambda handler."""
- if "stage" not in event:
- raise Exception("Error: Event must have `stage`.")
- return "ok %s v1.0.1" % event["stage"]
View
@@ -0,0 +1,28 @@
+{
+ "name": "c4se-infra",
+ "version": "1.0.0",
+ "description": "c4se's infrastructure code.",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/ne-sachirou/c4se-infra.git"
+ },
+ "keywords": [
+ "infrastructure"
+ ],
+ "author": "Sachiro Inoue <utakata.c4se@gmail.com>",
+ "license": "GPL-3.0",
+ "bugs": {
+ "url": "https://github.com/ne-sachirou/c4se-infra/issues"
+ },
+ "homepage": "https://github.com/ne-sachirou/c4se-infra#readme",
+ "dependencies": {
+ "serverless": "^0.5.6"
+ },
+ "devDependencies": {
+ "npm-check-updates": "^2.8.0"
+ }
+}
File renamed without changes.
Oops, something went wrong.

0 comments on commit 0105163

Please sign in to comment.