Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oldsj committed Jan 13, 2018
0 parents commit 94045d3
Show file tree
Hide file tree
Showing 45 changed files with 12,224 additions and 0 deletions.
120 changes: 120 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@

# Created by https://www.gitignore.io/api/python,serverless,visualstudiocode

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule.*

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

### Serverless ###
# Ignore build directory
.serverless

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history


# End of https://www.gitignore.io/api/python,serverless,visualstudiocode
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Python36\\python.exe"
}
39 changes: 39 additions & 0 deletions execution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"roleName": "monitor-serverless-dev-us-east-2-lambdaRole",
"policies": [
{
"document": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogStream"
],
"Resource": [
"arn:aws:logs:us-east-2:302146712672:log-group:/aws/lambda/monitor-serverless-dev-hello:*"
],
"Effect": "Allow"
},
{
"Action": [
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:us-east-2:302146712672:log-group:/aws/lambda/monitor-serverless-dev-hello:*:*"
],
"Effect": "Allow"
},
{
"Action": [
"sns:ListBucket"
],
"Resource": "arn:aws:s3:::monitor-serverless-dev-serverlessdeploymentbucket-50lfahtpibcv",
"Effect": "Allow"
}
]
},
"name": "dev-monitor-serverless-lambda",
"type": "inline"
}
]
}
43 changes: 43 additions & 0 deletions handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import boto3
import urllib3
import os

def hello(event, context):
client = boto3.client('sns')

http = urllib3.PoolManager(timeout=5.0)
try:
r = http.request('GET', 'http://www.oscn.net/v4')

if r.status == 201:
body = {
"message": "OSCN is UPPP!!11!"
}
else:
body = {
"message": "OSCN is dowwwwn :("
}
client.publish(
PhoneNumber="+14059266362",
Message="OSCN is dowwwwn :("
)

response = {
"statusCode": 500,
"body": json.dumps(body)
}

return response

except urllib3.exceptions.MaxRetryError as e:
body = {
"message": "Service is down for unknown reason"
}

response = {
"statusCode": 500,
"body": json.dumps(body)
}

return response
103 changes: 103 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!

service: monitor-serverless

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
name: aws
runtime: python3.6

# you can overwrite defaults here
stage: dev
region: us-east-2

# you can add statements to the Lambda function's IAM Role here
iamRoleStatements:
- Effect: "Allow"
Action:
- "sns:ListBucket"
Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
# - Effect: "Allow"
# Action:
# - "s3:PutObject"
# Resource:
# Fn::Join:
# - ""
# - - "arn:aws:s3:::"
# - "Ref" : "ServerlessDeploymentBucket"
# - "/*"

# you can define service wide environment variables here
# environment:
# variable1: value1

# you can add packaging information here
package:
#include:
# - modules/**
#exclude:
# - modules/boto3/**
# - modules/boto3/**

functions:
hello:
handler: handler.hello

# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
events:
- http:
path: /
method: get
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
# - alexaSkill
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
# - iot:
# sql: "SELECT * FROM 'some_topic'"
# - cloudwatchEvent:
# event:
# source:
# - "aws.ec2"
# detail-type:
# - "EC2 Instance State-change Notification"
# detail:
# state:
# - pending
# - cloudwatchLog: '/aws/lambda/hello'
# - cognitoUserPool:
# pool: MyUserPool
# trigger: PreSignUp

# Define function environment variables here
# environment:
# variable2: value2

# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"
Loading

0 comments on commit 94045d3

Please sign in to comment.