Skip to content

Commit fdaddff

Browse files
committed
Initialized the project using serverless create command
0 parents  commit fdaddff

File tree

7 files changed

+182
-0
lines changed

7 files changed

+182
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# package directories
2+
node_modules
3+
jspm_packages
4+
5+
# Serverless directories
6+
.serverless
7+
8+
# Webpack directories
9+
.webpack

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Lambda",
5+
"type": "node",
6+
"request": "launch",
7+
"runtimeArgs": ["--inspect", "--debug-port=9229"],
8+
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
9+
"args": ["offline"],
10+
"port": 9229,
11+
"console": "integratedTerminal"
12+
}
13+
]
14+
}

handler.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import "source-map-support/register";
2+
3+
import { APIGatewayProxyHandler } from "aws-lambda";
4+
5+
export const hello: APIGatewayProxyHandler = async (event, _context) => {
6+
return {
7+
statusCode: 200,
8+
body: JSON.stringify(
9+
{
10+
message:
11+
"Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!",
12+
input: event,
13+
},
14+
null,
15+
2
16+
),
17+
};
18+
};

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "aws-lambda-github-pipeline",
3+
"version": "1.0.0",
4+
"description": "Serverless webpack example using Typescript",
5+
"main": "handler.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"dependencies": {
10+
"source-map-support": "^0.5.10"
11+
},
12+
"devDependencies": {
13+
"@types/aws-lambda": "^8.10.17",
14+
"@types/node": "^10.12.18",
15+
"@types/serverless": "^1.72.5",
16+
"fork-ts-checker-webpack-plugin": "^3.0.1",
17+
"serverless-webpack": "^5.2.0",
18+
"ts-loader": "^5.3.3",
19+
"ts-node": "^8.10.2",
20+
"typescript": "^3.2.4",
21+
"webpack": "^4.29.0",
22+
"webpack-node-externals": "^1.7.2"
23+
},
24+
"author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)",
25+
"license": "MIT"
26+
}

serverless.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { Serverless } from 'serverless/aws';
2+
3+
const serverlessConfiguration: Serverless = {
4+
service: {
5+
name: 'aws-lambda-github-pipeline',
6+
// app and org for use with dashboard.serverless.com
7+
// app: your-app-name,
8+
// org: your-org-name,
9+
},
10+
frameworkVersion: '2',
11+
custom: {
12+
webpack: {
13+
webpackConfig: './webpack.config.js',
14+
includeModules: true
15+
}
16+
},
17+
// Add the serverless-webpack plugin
18+
plugins: ['serverless-webpack'],
19+
provider: {
20+
name: 'aws',
21+
runtime: 'nodejs12.x',
22+
apiGateway: {
23+
minimumCompressionSize: 1024,
24+
},
25+
environment: {
26+
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
27+
},
28+
},
29+
functions: {
30+
hello: {
31+
handler: 'handler.hello',
32+
events: [
33+
{
34+
http: {
35+
method: 'get',
36+
path: 'hello',
37+
}
38+
}
39+
]
40+
}
41+
}
42+
}
43+
44+
module.exports = serverlessConfiguration;

tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2017"],
4+
"removeComments": true,
5+
"moduleResolution": "node",
6+
"noUnusedLocals": true,
7+
"noUnusedParameters": true,
8+
"sourceMap": true,
9+
"target": "es2017",
10+
"outDir": "lib"
11+
},
12+
"include": ["./**/*.ts"],
13+
"exclude": [
14+
"node_modules/**/*",
15+
".serverless/**/*",
16+
".webpack/**/*",
17+
"_warmup/**/*",
18+
".vscode/**/*"
19+
]
20+
}

webpack.config.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const path = require('path');
2+
const slsw = require('serverless-webpack');
3+
const nodeExternals = require('webpack-node-externals');
4+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
5+
6+
module.exports = {
7+
context: __dirname,
8+
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
9+
entry: slsw.lib.entries,
10+
devtool: slsw.lib.webpack.isLocal ? 'cheap-module-eval-source-map' : 'source-map',
11+
resolve: {
12+
extensions: ['.mjs', '.json', '.ts'],
13+
symlinks: false,
14+
cacheWithContext: false,
15+
},
16+
output: {
17+
libraryTarget: 'commonjs',
18+
path: path.join(__dirname, '.webpack'),
19+
filename: '[name].js',
20+
},
21+
target: 'node',
22+
externals: [nodeExternals()],
23+
module: {
24+
rules: [
25+
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
26+
{
27+
test: /\.(tsx?)$/,
28+
loader: 'ts-loader',
29+
exclude: [
30+
[
31+
path.resolve(__dirname, 'node_modules'),
32+
path.resolve(__dirname, '.serverless'),
33+
path.resolve(__dirname, '.webpack'),
34+
],
35+
],
36+
options: {
37+
transpileOnly: true,
38+
experimentalWatchApi: true,
39+
},
40+
},
41+
],
42+
},
43+
plugins: [
44+
// new ForkTsCheckerWebpackPlugin({
45+
// eslint: true,
46+
// eslintOptions: {
47+
// cache: true
48+
// }
49+
// })
50+
],
51+
};

0 commit comments

Comments
 (0)