AWS Lambda: Advanced Coding Session (slides)
Live demos:
- Amazon API Gateway Access Control
- Amazon Kinesis Streams processing
- Amazon Cognito Sync trigger
- AWS CloudFormation Custom Resources
Live demos:
import boto3 | |
iam = boto3.resource('iam') | |
def get_policy_body(arn, version_id=None): | |
""" Return IAM Policy JSON body """ | |
if version_id: | |
version = iam.PolicyVersion(arn, version_id) | |
else: | |
policy = iam.Policy(arn) |
def lambda_handler(event, context): | |
name = event.get('name') or 'World' | |
print("Name: %s" % name) | |
return "Hello %s!" % name |
#!/bin/bash | |
BUCKET="YOUR_BUCKET_NAME" # bucket name | |
FILENAME="deployment-package.zip" # upload key | |
TMP_FOLDER="/tmp/lambda-env-tmp/" # will be cleaned | |
OUTPUT_FOLDER="/tmp/lambda-env/" # will be cleaned | |
HERE=${BASH_SOURCE%/*} # relative path to this file's folder | |
LAMBDA_FOLDER="$HERE/lambda/" # relative path |
def from_sklearn(docs,vect,lda,**kwargs): | |
"""Create Prepared Data from sklearn's vectorizer and Latent Dirichlet | |
Application | |
Parameters | |
---------- | |
docs : Pandas Series. | |
Documents to be passed as an input. | |
vect : Scikit-Learn Vectorizer (CountVectorizer,TfIdfVectorizer). |
# List unique values in a DataFrame column | |
pd.unique(df.column_name.ravel()) | |
# Convert Series datatype to numeric, getting rid of any non-numeric values | |
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True) | |
# Grab DataFrame rows where column has certain values | |
valuelist = ['value1', 'value2', 'value3'] | |
df = df[df.column.isin(valuelist)] |
import os | |
import math | |
import re | |
import pandas as pd | |
from collections import Counter | |
from sklearn.datasets import fetch_20newsgroups | |
#get a subset of the dataset | |
categories = [ |