Skip to content

Instantly share code, notes, and snippets.

@chenrui333
Created June 19, 2018 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenrui333/30673fac7c364eeb67279877ba4d0246 to your computer and use it in GitHub Desktop.
Save chenrui333/30673fac7c364eeb67279877ba4d0246 to your computer and use it in GitHub Desktop.

python-serverless-sample

import json
from datadog import initialize, ThreadStats
def hello(event, context):
initialize()
stats = ThreadStats()
stats.start()
body = {
"message": "Go Serverless v1.0! Your function executed successfully!",
"input": event
}
stats.increment('pro.serverless.lambda_python_sample.prod')
response = {
"statusCode": 200,
"body": json.dumps(body["message"])
}
return response
{
"name": "serverless-python-sample",
"description": "",
"version": "0.1.0",
"dependencies": {},
"devDependencies": {
"serverless-offline-python": "^3.21.2",
"serverless-python-requirements": "^4.0.4"
}
}
service: serverless-python-sample
# sls version
frameworkVersion: ">=1.27.0 < 2.0.0"
provider:
name: aws
runtime: python3.6
stage: local
region: us-east-1
iamRoleStatements:
- Effect: "Allow"
Action:
- ssm:GetParameter
Resource:
- "arn:aws:ssm:us-east-1:123:parameter/pro/datadog-api-key"
- "arn:aws:ssm:us-east-1:123:parameter/pro/datadog-app-key"
- Effect: "Allow"
Action:
- kms:Decrypt
Resource: "arn:aws:kms:us-east-1:123:key/321"
plugins:
- serverless-offline-python
- serverless-python-requirements
custom:
stage: "${opt:stage, self:provider.stage}"
prod:
events:
- http:
method: GET
path: /hello
local:
events:
- http:
method: GET
path: /hello
serverless-offline:
port: 4000
functions:
hello:
handler: handler.hello
environment:
DATADOG_API_KEY: ${ssm:/pro/datadog-api-key~true}
DATADOG_APP_KEY: ${ssm:/pro/datadog-app-key~true}
events: ${self:custom.${self:custom.stage}.events}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment