Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Commit 6b082b5

Browse files
committed
First commit
0 parents  commit 6b082b5

File tree

8 files changed

+3945
-0
lines changed

8 files changed

+3945
-0
lines changed

.babelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"plugins": ["source-map-support", "transform-runtime"],
3+
"presets": [
4+
["env", {
5+
"targets": {
6+
"node": "8.10"
7+
},
8+
"useBuiltIns": true
9+
}],
10+
"stage-3"
11+
]
12+
}

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# package directories
2+
node_modules
3+
jspm_packages
4+
5+
# Serverless directories
6+
.serverless
7+
.webpack
8+
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Intellij IDEA
14+
.idea
15+
*.iml
16+
17+
# VisualStudioCode
18+
.vscode/*
19+
!.vscode/settings.json
20+
!.vscode/tasks.json
21+
!.vscode/launch.json
22+
!.vscode/extensions.json
23+
.history

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# aws-nodejs8-webpack-offline
2+
3+
This is a template you can use to quickly create a Serverless service with configured
4+
`serverless-webpack`, `serverless-offline`, and optionally `serverless-dynamodb-local`.
5+
We added AWS SDK for your convenience as well.
6+
7+
If you're looking for out-of-box HTTP support, check out our template for Koa:
8+
[aws-nodejs8-koa](https://github.com/aproint/aws-nodejs8-koa)
9+
10+
## How to use
11+
12+
```
13+
sls create --template-url https://github.com/aproint/aws-nodejs8-webpack-offline --path myservice
14+
```

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "aws-nodejs8-webpack-offline",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"private": true,
6+
"devDependencies": {
7+
"babel-core": "^6.26.3",
8+
"babel-loader": "^7.1.4",
9+
"babel-plugin-source-map-support": "^2.0.1",
10+
"babel-plugin-transform-runtime": "^6.23.0",
11+
"babel-preset-env": "^1.7.0",
12+
"babel-preset-stage-3": "^6.24.1",
13+
"serverless-offline": "^3.25.4",
14+
"serverless-webpack": "^5.1.5",
15+
"webpack": "^4.12.0",
16+
"webpack-node-externals": "^1.7.2"
17+
},
18+
"dependencies": {
19+
"aws-sdk": "^2.255.1",
20+
"babel-runtime": "^6.26.0",
21+
"serverless-dynamodb-local": "^0.2.30",
22+
"source-map-support": "^0.5.6"
23+
},
24+
"scripts": {
25+
"fixdb": "sls dynamodb remove && sls dynamodb install",
26+
"start": "sls offline start"
27+
}
28+
}

serverless.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Welcome to Serverless!
2+
#
3+
# This file is the main config file for your service.
4+
# It's very minimal at this point and uses default values.
5+
# You can always add more config options for more control.
6+
# We've included some commented out config examples here.
7+
# Just uncomment any of them to get that config option.
8+
#
9+
# For full config options, check the docs:
10+
# docs.serverless.com
11+
#
12+
# Happy Coding!
13+
14+
service: aws-nodejs8-webpack-offline
15+
16+
# You can pin your service to only deploy with a specific Serverless version
17+
# Check out our docs for more details
18+
# frameworkVersion: "=X.X.X"
19+
20+
# The plugins need to be ordered as follows.
21+
plugins:
22+
- serverless-webpack
23+
# Uncomment to add local dynamodb support
24+
# - serverless-dynamodb-local
25+
- serverless-offline
26+
27+
custom:
28+
webpack:
29+
includeModules:
30+
forceExclude:
31+
- aws-sdk
32+
packager: 'yarn' # Packager that will be used to package your external modules
33+
# dynamodb:
34+
# start:
35+
# migrate: true
36+
# seed: false
37+
serverless-offline:
38+
#httpsProtocol: "dev-certs"
39+
#port: 4000
40+
41+
provider:
42+
name: aws
43+
runtime: nodejs8.10
44+
45+
# you can overwrite defaults here
46+
# stage: dev
47+
# region: us-east-1
48+
49+
# you can add statements to the Lambda function's IAM Role here
50+
# iamRoleStatements:
51+
# - Effect: "Allow"
52+
# Action:
53+
# - "s3:ListBucket"
54+
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
55+
# - Effect: "Allow"
56+
# Action:
57+
# - "s3:PutObject"
58+
# Resource:
59+
# Fn::Join:
60+
# - ""
61+
# - - "arn:aws:s3:::"
62+
# - "Ref" : "ServerlessDeploymentBucket"
63+
# - "/*"
64+
65+
# you can define service wide environment variables here
66+
# environment:
67+
# variable1: value1
68+
69+
# you can add packaging information here
70+
#package:
71+
# include:
72+
# - include-me.js
73+
# - include-me-dir/**
74+
# exclude:
75+
# - exclude-me.js
76+
# - exclude-me-dir/**
77+
78+
functions:
79+
hello:
80+
handler: src/handler.handle
81+
82+
# The following are a few example events you can configure
83+
# NOTE: Please make sure to change your handler code to work with those events
84+
# Check the event documentation for details
85+
# events:
86+
# - http:
87+
# path: users/create
88+
# method: get
89+
# - s3: ${env:BUCKET}
90+
# - schedule: rate(10 minutes)
91+
# - sns: greeter-topic
92+
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
93+
# - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
94+
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
95+
# - iot:
96+
# sql: "SELECT * FROM 'some_topic'"
97+
# - cloudwatchEvent:
98+
# event:
99+
# source:
100+
# - "aws.ec2"
101+
# detail-type:
102+
# - "EC2 Instance State-change Notification"
103+
# detail:
104+
# state:
105+
# - pending
106+
# - cloudwatchLog: '/aws/lambda/hello'
107+
# - cognitoUserPool:
108+
# pool: MyUserPool
109+
# trigger: PreSignUp
110+
111+
# Define function environment variables here
112+
# environment:
113+
# variable2: value2
114+
115+
# You can add CloudFormation resource templates here
116+
#resources:
117+
# Resources:
118+
# yourDynamoDbTable:
119+
# Type: AWS::DynamoDB::Table
120+
# Properties:
121+
# TableName: YourDynamoDbTable
122+
# AttributeDefinitions:
123+
# - AttributeName: id
124+
# AttributeType: S
125+
# KeySchema:
126+
# - AttributeName: id
127+
# KeyType: HASH
128+
# ProvisionedThroughput:
129+
# ReadCapacityUnits: 5
130+
# WriteCapacityUnits: 5
131+
# NewResource:
132+
# Type: AWS::S3::Bucket
133+
# Properties:
134+
# BucketName: my-new-bucket
135+
# Outputs:
136+
# NewOutput:
137+
# Description: "Description for the output"
138+
# Value: "Some output value"

src/handler.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const handle = async (event, context) => {
2+
console.log(event)
3+
if (event.error) {
4+
throw new Error('There was a serious error!')
5+
}
6+
return 'great success!'
7+
}

webpack.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const slsw = require('serverless-webpack');
2+
const nodeExternals = require("webpack-node-externals");
3+
4+
module.exports = {
5+
entry: slsw.lib.entries,
6+
target: "node",
7+
// Generate sourcemaps for proper error messages
8+
devtool: 'source-map',
9+
// Since 'aws-sdk' is not compatible with webpack,
10+
// we exclude all node dependencies
11+
externals: [nodeExternals()],
12+
mode: slsw.lib.webpack.isLocal ? "development" : "production",
13+
optimization: {
14+
// We no not want to minimize our code.
15+
minimize: false
16+
},
17+
performance: {
18+
// Turn off size warnings for entry points
19+
hints: false
20+
},
21+
// Run babel on all .js files and skip those in node_modules
22+
module: {
23+
rules: [
24+
{
25+
test: /\.js$/,
26+
loader: "babel-loader",
27+
include: __dirname,
28+
exclude: /node_modules/
29+
}
30+
]
31+
}
32+
};

0 commit comments

Comments
 (0)