Skip to content

Commit bcebdec

Browse files
authored
Merge pull request #3 from bennybauer/issue2-proxy_lambda
fix issue #2 - support lambda-proxy changes
2 parents 1bac6dd + 3b23496 commit bcebdec

File tree

9 files changed

+173
-138
lines changed

9 files changed

+173
-138
lines changed

.gitignore

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,66 @@
1-
# Created by https://www.gitignore.io/api/pycharm
21

3-
### PyCharm ###
4-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
5-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
2+
# Created by https://www.gitignore.io/api/python,visualstudiocode,node,serverless
63

7-
# User-specific stuff:
8-
.idea/workspace.xml
9-
.idea/tasks.xml
10-
.idea/dictionaries
11-
.idea/vcs.xml
12-
.idea/jsLibraryMappings.xml
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
24+
# nyc test coverage
25+
.nyc_output
26+
27+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
.grunt
1329

14-
# Sensitive or high-churn files:
15-
.idea/dataSources.ids
16-
.idea/dataSources.xml
17-
.idea/dataSources.local.xml
18-
.idea/sqlDataSources.xml
19-
.idea/dynamic.xml
20-
.idea/uiDesigner.xml
30+
# Bower dependency directory (https://bower.io/)
31+
bower_components
2132

22-
# Gradle:
23-
.idea/gradle.xml
24-
.idea/libraries
33+
# node-waf configuration
34+
.lock-wscript
2535

26-
# Mongo Explorer plugin:
27-
.idea/mongoSettings.xml
36+
# Compiled binary addons (http://nodejs.org/api/addons.html)
37+
build/Release
2838

29-
## File-based project format:
30-
*.iws
39+
# Dependency directories
40+
node_modules/
41+
jspm_packages/
3142

32-
## Plugin-specific files:
43+
# Typescript v1 declaration files
44+
typings/
3345

34-
# IntelliJ
35-
/out/
36-
.idea
46+
# Optional npm cache directory
47+
.npm
3748

38-
# mpeltonen/sbt-idea plugin
39-
.idea_modules/
49+
# Optional eslint cache
50+
.eslintcache
4051

41-
# JIRA plugin
42-
atlassian-ide-plugin.xml
52+
# Optional REPL history
53+
.node_repl_history
4354

44-
# Crashlytics plugin (for Android Studio and IntelliJ)
45-
com_crashlytics_export_strings.xml
46-
crashlytics.properties
47-
crashlytics-build.properties
48-
fabric.properties
55+
# Output of 'npm pack'
56+
*.tgz
4957

50-
### PyCharm Patch ###
51-
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
58+
# Yarn Integrity file
59+
.yarn-integrity
5260

53-
# *.iml
54-
# modules.xml
55-
# .idea/misc.xml
56-
# *.ipr
61+
# dotenv environment variables file
62+
.env
5763

58-
# Created by https://www.gitignore.io/api/python
5964

6065
### Python ###
6166
# Byte-compiled / optimized / DLL files
@@ -80,6 +85,7 @@ lib64/
8085
parts/
8186
sdist/
8287
var/
88+
wheels/
8389
*.egg-info/
8490
.installed.cfg
8591
*.egg
@@ -110,7 +116,6 @@ coverage.xml
110116
*.pot
111117

112118
# Django stuff:
113-
*.log
114119
local_settings.py
115120

116121
# Flask stuff:
@@ -126,7 +131,7 @@ docs/_build/
126131
# PyBuilder
127132
target/
128133

129-
# IPython Notebook
134+
# Jupyter Notebook
130135
.ipynb_checkpoints
131136

132137
# pyenv
@@ -135,23 +140,32 @@ target/
135140
# celery beat schedule file
136141
celerybeat-schedule
137142

143+
# SageMath parsed files
144+
*.sage.py
145+
138146
# dotenv
139-
.env
140147

141148
# virtualenv
142-
.venv/
149+
.venv
143150
venv/
144151
ENV/
145152

146153
# Spyder project settings
147154
.spyderproject
155+
.spyproject
148156

149157
# Rope project settings
150158
.ropeproject
151159

152-
# Mac
153-
.DS_Store
160+
# mkdocs documentation
161+
/site
154162

155-
# Serverless
163+
### Serverless ###
164+
# Ignore build directory
156165
.serverless
157-
vendored
166+
.requirements
167+
168+
### VisualStudioCode ###
169+
.vscode
170+
171+
# End of https://www.gitignore.io/api/python,visualstudiocode,node,serverless

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Benny Bauer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,10 @@ The service has a dependency on external package (`requests`) and it exposes 2 R
2626

2727

2828
## Deployment
29-
Create dependencies folder for packaging
3029

31-
pip install -t vendored -r requirements.txt
32-
33-
And... deploy!
34-
3530
sls deploy
36-
31+
3732
### Invocation
38-
You can trigger a function:
39-
40-
# Invoke function without input
41-
sls invoke -f listposts
42-
43-
# Provide input
44-
sls invoke -f getpost -p event.json
45-
46-
or
4733

4834
curl <host>/posts
4935
curl <host>/posts/5
@@ -79,4 +65,4 @@ Run a specific function with a provided input and get the logs
7965
sls invoke -f <function-name> -p event.json -l
8066

8167
# Credits
82-
[JSONPlaceholder](https://jsonplaceholder.typicode.com) by [@typicode](https://github.com/typicode) is used for the posts backend.
68+
[JSONPlaceholder](https://jsonplaceholder.typicode.com) by [@typicode](https://github.com/typicode) is used for the posts backend.

event.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

handler.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
# get this file's directory independent of where it's run from
2-
import sys, os
3-
4-
here = os.path.dirname(os.path.realpath(__file__))
5-
sys.path.append(os.path.join(here, "./vendored"))
6-
7-
import requests
81
import logging
2+
import requests
93

104
log = logging.getLogger()
115
log.setLevel(logging.DEBUG)
@@ -14,14 +8,30 @@
148

159

1610
def list_posts(event, context):
11+
""" Retrieve posts list """
1712
url = API_HOST + '/posts'
1813

1914
log.debug('calling ' + url)
20-
return requests.get(url).json()
15+
res = requests.get(url)
16+
17+
response = {
18+
"statusCode": res.status_code,
19+
"body": res.text
20+
}
21+
22+
return response
2123

2224

2325
def get_post(event, context):
24-
url = API_HOST + '/posts/' + event['path']['id']
26+
""" Retrieve post by id """
27+
url = API_HOST + '/posts/' + str(event['pathParameters']['id'])
2528

2629
log.debug('calling ' + url)
27-
return requests.get(url).json()
30+
res = requests.get(url)
31+
32+
response = {
33+
"statusCode": res.status_code,
34+
"body": res.text
35+
}
36+
37+
return response

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "serverless-python-sample",
3+
"version": "1.0.1",
4+
"description": "A simple serverless python sample",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "python test.py"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/bennybauer/serverless-python-sample.git"
12+
},
13+
"keywords": [
14+
"python",
15+
"aws",
16+
"lambda",
17+
"serverless"
18+
],
19+
"author": "bennybauer",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/bennybauer/serverless-python-sample/issues"
23+
},
24+
"homepage": "https://github.com/bennybauer/serverless-python-sample#readme",
25+
"dependencies": {
26+
"serverless-python-requirements": "^2.2.1"
27+
}
28+
}

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
requests==2.11.1
2-
wheel==0.24.0
1+
requests==2.13.0

serverless.yml

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,13 @@
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-
141
service: posts
152

163
provider:
174
name: aws
185
runtime: python2.7
196
memorySize: 128
20-
# you can add statements to the Lambda function's IAM Role here
21-
# iamRoleStatements:
22-
# - Effect: "Allow"
23-
# Action:
24-
# - "s3:ListBucket"
25-
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
26-
# - Effect: "Allow"
27-
# Action:
28-
# - "s3:PutObject"
29-
# Resource:
30-
# Fn::Join:
31-
# - ""
32-
# - - "arn:aws:s3:::"
33-
# - "Ref" : "ServerlessDeploymentBucket"
34-
35-
# you can overwrite defaults here
36-
#defaults:
37-
# stage: dev
38-
# region: us-east-1
397

40-
# you can add packaging information here
41-
#package:
42-
# include:
43-
# - include-me.js
44-
# exclude:
45-
# - exclude-me.js
46-
# artifact: my-service-code.zip
8+
package:
9+
exclude:
10+
- test.py
4711

4812
functions:
4913
listPosts:
@@ -52,9 +16,6 @@ functions:
5216
- http:
5317
path: posts
5418
method: get
55-
# - s3: ${env.BUCKET}
56-
# - schedule: rate(10 minutes)
57-
# - sns: greeter-topic
5819

5920
getPost:
6021
handler: handler.get_post
@@ -63,14 +24,5 @@ functions:
6324
path: posts/{id}
6425
method: get
6526

66-
# you can add CloudFormation resource templates here
67-
#resources:
68-
# Resources:
69-
# NewResource:
70-
# Type: AWS::S3::Bucket
71-
# Properties:
72-
# BucketName: my-new-bucket
73-
# Outputs:
74-
# NewOutput:
75-
# Description: "Description for the output"
76-
# Value: "Some output value
27+
plugins:
28+
- serverless-python-requirements

0 commit comments

Comments
 (0)