Skip to content

Instantly share code, notes, and snippets.

url = 'https://api.twitter.com/1.1/account_activity/all/env-beta/subscriptions.json'
r = twitter.post(url)
from requests_oauthlib import OAuth1Session
import urllib
CONSUMER_KEY = 'adsklfjlaksdjfasldfk'
CONSUMER_SECRET = 'aksdjfkjljasdfljLIJSDLKFjlskdjflaskjdfa'
ACCESS_TOKEN = '0923840928349082390283-kljadsflkJKLDfjdslkjklajkljdsfls'
ACCESS_SECRET = '098asdfkljLSkdjfsda09uaskdjflLKJESF'
twitter = OAuth1Session(CONSUMER_KEY,
client_secret=CONSUMER_SECRET,
@nragusa
nragusa / crc.py
Last active March 10, 2018 16:11
def crc(event, context):
""" Returns a CRC (Challenge Response Check) to keep this webhook
secure. https://goo.gl/kFdJgV for more details. """
# Short circuit ping from CloudWatch Events
if event.get('source', None) == 'aws.events':
print('ping')
return
import base64
import hmac
import uuid
import json
import boto3
from botocore.vendored import requests
"""
CloudFormation Template has the following components:
# A defintion of your lambda function (what's included below) that
# creates your custom resource
#!/usr/bin/env python
import boto3
import os
from botocore.exceptions import ClientError
# CONFIGURATION
BUCKET_NAME = 'mybucketname'
DRY_RUN = True
S3 = boto3.client('s3')
---
swagger: "2.0"
info:
version: "1.0"
title: "s3-sns-lambda"
basePath: "/dev"
schemes:
- "https"
paths:
/:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: ./swagger.yaml
StageName: !Ref ApiGatewayStage
Variables:
LambdaFunctionName: !Ref LambdaSNS
LambdaSNS:
Type: AWS::Serverless::Function
Properties:
def sendResponse(event, reason, status):
response = {
'Status': status,
'Reason': reason,
'PhysicalResourceId': 'physical-resource-id',
'StackId': event['StackId'],
'RequestId': event['RequestId'],
'LogicalResourceId': event['LogicalResourceId']
}
print(response)
from aws_xray_sdk.core import xray_recorder
def get_random_ints(count):
"""Returns a list of random integers of size count.
"""
print 'Generating random ints'
subsegment = xray_recorder.begin_subsegment('generating_random_ints')
my_nums = []
for i in range(count):
my_nums.append(randrange(10000))
xray_recorder.end_subsegment()
CodePipelineServiceRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument: |
{
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": [ "codepipeline.amazonaws.com" ]},
"Action": [ "sts:AssumeRole" ]