diff --git a/blog/graphql/event.json b/blog/graphql/event.json deleted file mode 100644 index 9e26dfe..0000000 --- a/blog/graphql/event.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/blog/graphql/s-function.json b/blog/graphql/s-function.json deleted file mode 100644 index 7c9e23c..0000000 --- a/blog/graphql/s-function.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "name": "graphql", - "runtime": "nodejs4.3", - "description": "Serverless Lambda function for project: serverless-graphql-blog", - "customName": false, - "customRole": false, - "handler": "graphql/handler.handler", - "timeout": 6, - "memorySize": 1024, - "authorizer": {}, - "custom": { - "excludePatterns": [], - "optimize": { - "exclude": [ - "aws-sdk" - ], - "transforms": [ - { - "name": "babelify", - "opts": { - "presets": [ - "es2015" - ] - } - } - ] - } - }, - "endpoints": [ - { - "path": "blog/graphql", - "method": "POST", - "type": "AWS", - "authorizationType": "none", - "authorizerFunction": false, - "apiKeyRequired": false, - "requestParameters": {}, - "requestTemplates": { - "application/json": "{\"query\" : $input.json(\"$\")}" - }, - "responses": { - "400": { - "statusCode": "400" - }, - "default": { - "statusCode": "200", - "responseParameters": {}, - "responseModels": {}, - "responseTemplates": {}, - "application/json": "" - } - } - } - ], - "events": [], - "environment": { - "SERVERLESS_PROJECT": "${project}", - "SERVERLESS_STAGE": "${stage}", - "SERVERLESS_REGION": "${region}" - }, - "vpc": { - "securityGroupIds": [], - "subnetIds": [] - } -} \ No newline at end of file diff --git a/blog/graphql/s-templates.json b/blog/graphql/s-templates.json deleted file mode 100644 index afe2b92..0000000 --- a/blog/graphql/s-templates.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "resourceTemplate": {} -} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9d47134 --- /dev/null +++ b/index.js @@ -0,0 +1,7 @@ +'use strict'; + +import graphql from './blog/graphql/handler' + +// Lambda Handler +export default { graphql } + diff --git a/s-project.json b/s-project.json deleted file mode 100644 index bf212d9..0000000 --- a/s-project.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "serverless-graphql-blog", - "custom": {}, - "plugins": [ - "serverless-optimizer-plugin" - ] -} \ No newline at end of file diff --git a/s-resources-cf.json b/s-resources-cf.json deleted file mode 100644 index 24ed7a2..0000000 --- a/s-resources-cf.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "The AWS CloudFormation template for this Serverless application's resources outside of Lambdas and Api Gateway", - "Resources": { - "IamRoleLambda": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - }, - "Action": [ - "sts:AssumeRole" - ] - } - ] - }, - "Path": "/" - } - }, - "IamPolicyLambda": { - "Type": "AWS::IAM::Policy", - "Properties": { - "PolicyName": "${stage}-${project}-lambda", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "logs:CreateLogGroup", - "logs:CreateLogStream", - "logs:PutLogEvents" - ], - "Resource": "arn:aws:logs:${region}:*:*" - }, - { - "Effect": "Allow", - "Action": [ - "*" - ], - "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-posts-${stage}" - }, - { - "Effect": "Allow", - "Action": [ - "*" - ], - "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-authors-${stage}" - }, - { - "Effect": "Allow", - "Action": [ - "*" - ], - "Resource": "arn:aws:dynamodb:${region}:*:table/${project}-comments-${stage}" - } - ] - }, - "Roles": [ - { - "Ref": "IamRoleLambda" - } - ] - } - }, - "PostsDynamo": { - "Type": "AWS::DynamoDB::Table", - "DeletionPolicy": "Retain", - "Properties": { - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "AttributeName": "id", - "KeyType": "HASH" - } - ], - "ProvisionedThroughput": { - "ReadCapacityUnits": 1, - "WriteCapacityUnits": 1 - }, - "TableName": "${project}-posts-${stage}" - } - }, - "AuthorsDynamo": { - "Type": "AWS::DynamoDB::Table", - "DeletionPolicy": "Retain", - "Properties": { - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "AttributeName": "id", - "KeyType": "HASH" - } - ], - "ProvisionedThroughput": { - "ReadCapacityUnits": 1, - "WriteCapacityUnits": 1 - }, - "TableName": "${project}-authors-${stage}" - } - }, - "CommentsDynamo": { - "Type": "AWS::DynamoDB::Table", - "DeletionPolicy": "Retain", - "Properties": { - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "AttributeName": "id", - "KeyType": "HASH" - } - ], - "ProvisionedThroughput": { - "ReadCapacityUnits": 1, - "WriteCapacityUnits": 1 - }, - "TableName": "${project}-comments-${stage}" - } - } - }, - "Outputs": { - "IamRoleArnLambda": { - "Description": "ARN of the lambda IAM role", - "Value": { - "Fn::GetAtt": [ - "IamRoleLambda", - "Arn" - ] - } - } - } -} \ No newline at end of file diff --git a/serverless.env.yaml b/serverless.env.yaml new file mode 100644 index 0000000..9a5f83a --- /dev/null +++ b/serverless.env.yaml @@ -0,0 +1,10 @@ +vars: null +stages: + dev: + vars: null + regions: + us-west-2: + vars: + service: serverless-graphql-blog + stage: dev + diff --git a/serverless.yaml b/serverless.yaml new file mode 100644 index 0000000..707a5b2 --- /dev/null +++ b/serverless.yaml @@ -0,0 +1,84 @@ +service: "serverless-graphql-blog" +provider: "aws" +plugins: + - serverless-optimizer-plugin +functions: + sadiavas: + handler: "index.graphql" + include: + - blog/ + - index.js + events: + - http: + path: "blog/graphql" + method: "POST" + + custom: + excludePatterns: [] + optimize: + exclude: + - "aws-sdk" + transforms: + - + name: "babelify" + opts: + presets: + - "es2015" + +defaults: + stage: "dev" + region: "us-west-2" + memory: 1024 + timeout: 6 + +resources: + Resources: + PostsDynamo: + Type: "AWS::DynamoDB::Table" + DeletionPolicy: "Retain" + Properties: + AttributeDefinitions: + - + AttributeName: "id" + AttributeType: "S" + KeySchema: + - + AttributeName: "id" + KeyType: "HASH" + ProvisionedThroughput: + ReadCapacityUnits: 1 + WriteCapacityUnits: 1 + TableName: "${service}-posts-${stage}" + AuthorsDynamo: + Type: "AWS::DynamoDB::Table" + DeletionPolicy: "Retain" + Properties: + AttributeDefinitions: + - + AttributeName: "id" + AttributeType: "S" + KeySchema: + - + AttributeName: "id" + KeyType: "HASH" + ProvisionedThroughput: + ReadCapacityUnits: 1 + WriteCapacityUnits: 1 + TableName: "${service}-authors-${stage}" + CommentsDynamo: + Type: "AWS::DynamoDB::Table" + DeletionPolicy: "Retain" + Properties: + AttributeDefinitions: + - + AttributeName: "id" + AttributeType: "S" + KeySchema: + - + AttributeName: "id" + KeyType: "HASH" + ProvisionedThroughput: + ReadCapacityUnits: 1 + WriteCapacityUnits: 1 + TableName: "${service}-comments-${stage}" +