├── default-swagger.yaml ├── import-swagger.py ├── lambda-exec-policy.json ├── main.tf ├── output.tf └── variables.tf /default-swagger.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | swagger: "2.0" 3 | info: 4 | version: "2016-03-22T17:33:14Z" 5 | title: "${stack_name}" 6 | basePath: /"${stage_name}" 7 | schemes: 8 | - "https" 9 | paths: 10 | ${lambda_path}: 11 | post: 12 | responses: 13 | 200: 14 | description: "200 response" 15 | x-amazon-apigateway-integration: 16 | responses: 17 | .*: 18 | statusCode: "200" 19 | uri: "${lambda_function_full_arn}" 20 | httpMethod: "${http_method}" 21 | type: "aws" 22 | -------------------------------------------------------------------------------- /import-swagger.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys, yaml, json, os 4 | 5 | api_id = sys.argv[1] 6 | input_file = sys.argv[2] 7 | 8 | def read_json(arg): 9 | with open(arg, 'r') as data_file: 10 | return json.load(data_file) 11 | 12 | 13 | def read_yaml(arg): 14 | with open( arg, 'r') as stream: 15 | return yaml.load(stream) 16 | 17 | def read_file(arg): 18 | if (arg.endswith('.yaml')) or (arg.endswith('.yml')): 19 | return read_yaml(arg) 20 | elif m.endswith('.json'): 21 | return read_json(arg) 22 | 23 | content = read_file( input_file ) 24 | minimized = json.dumps(content) 25 | print minimized 26 | os.system("aws apigateway put-rest-api --rest-api-id {} --mode=merge --body='{}'".format(api_id, minimized)) -------------------------------------------------------------------------------- /lambda-exec-policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Action": [ 7 | "logs:CreateLogGroup", 8 | "logs:CreateLogStream", 9 | "logs:PutLogEvents" 10 | ], 11 | "Resource": [ "arn:aws:logs:*:*:*" ] 12 | }, 13 | { 14 | "Effect": "Allow", 15 | "Resource": "*", 16 | "Action": [ 17 | "ec2:DescribeInstances", 18 | "ec2:CreateNetworkInterface", 19 | "ec2:AttachNetworkInterface", 20 | "ec2:DescribeNetworkInterfaces", 21 | "autoscaling:CompleteLifecycleAction", 22 | "lambda:InvokeFunction" 23 | ] 24 | }, 25 | { 26 | "Effect": "Allow", 27 | "Action": [ 28 | "s3:PutObject", 29 | "s3:GetObject", 30 | "s3:PutObject", 31 | "s3:DeleteObject", 32 | "s3:ListBucket" 33 | ], 34 | "Resource": [ "arn:aws:s3:::*" ] 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | resource "null_resource" "zip_payload" { 2 | 3 | provisioner "local-exec" { 4 | command = < ${path.cwd}/.terraform/${var.stack_name}/swagger-${var.function_name}.yaml <