Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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
You can’t perform that action at this time.