Skip to content

Instantly share code, notes, and snippets.

@qtangs
qtangs / get_layer_packages.sh
Last active September 23, 2024 15:36
Get packages for AWS Lambda Layer
#!/bin/bash
export PKG_DIR="python"
rm -rf ${PKG_DIR} && mkdir -p ${PKG_DIR}
docker run --rm -v $(pwd):/foo -w /foo lambci/lambda:build-python3.6 \
pip install -r requirements.txt --no-deps -t ${PKG_DIR}
@qtangs
qtangs / requirements.txt
Created December 5, 2018 16:52
Requirements for Pandas v0.23 Layer
pandas==0.23.4
pytz==2018.7
@qtangs
qtangs / serverless.yaml
Last active December 9, 2018 15:19
sample-service's serverless configuration file
service: sample-service # Name of the service, which is used as a prefix to all function names. TODO: Update to your custom name.
frameworkVersion: ">=1.34.0" # Layers are supported from version 1.34
provider:
name: aws # Assuming this is for AWS Lambda.
stage: dev # Name of the stage, typically either dev/staging/prod (or production), this is also added to all function names. TODO: Update to your custom name.
profile: some-aws-profile # Name of the pre-configured AWS profile that is founnd in ~/.aws/confidentials. TODO: Update to your profile.
region: some-region # Name of the region to deploy all functions to. TODO: Update to your custom region.
runtime: python3.6 # AWS Lambda runtime
import numpy as np
import pandas as pd
def handler(event, context):
dates = pd.date_range('20181201', periods=6)
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
print(df)
START RequestId: 2cee0f93-f97c-11e8-be81-1d3426460e67 Version: $LATEST
A B C D
2018-12-01 0.837058 -0.997650 0.333986 -0.266099
2018-12-02 -1.824489 0.306344 2.331290 0.520816
2018-12-03 1.605077 -1.516653 0.161290 0.163109
2018-12-04 0.740779 0.481298 -0.111764 -0.548484
2018-12-05 0.861482 0.630950 -0.588095 -2.114341
2018-12-06 -0.511081 -0.181257 0.068638 -1.685518
END RequestId: 2cee0f93-f97c-11e8-be81-1d3426460e67
REPORT RequestId: 2cee0f93-f97c-11e8-be81-1d3426460e67 Duration: 297.16 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 90 MB
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "The AWS CloudFormation template for this Serverless application",
"Resources": {
"ServerlessDeploymentBucket": {
"Type": "AWS::S3::Bucket"
},
"DataAnalysisLogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
@qtangs
qtangs / serverless_services.csv
Last active December 16, 2018 08:29
Serverless services vs non-serverlesss equivalents
Serverless Non-serverless
Compute AWS Lambda; Azure Functions; Google Cloud Functions ... AWS EC2; AWS ECS; Azure VMs ...
File Storage AWS S3; Azure Storage; Google Cloud Storage ... Hosted Network File System ...
Database Storage Parse; Firebase; AWS DynamoDB; AWS Aurora Serverless ... AWS RDS; Hosted NoSQL; ...
Event Stream AWS Kinesis; Azure Event Hubs; Google Cloud Pub/Sub ... Hosted Kafka; Message Queue ...
Authentication Auth0; AWS Cognito; Azure App Service Authentication ... Hosted Authentication logic ...
Workflows AWS Step Function; Azure Logic Apps ... Hosted Workflow Management ...
@qtangs
qtangs / Dockerfile
Created April 27, 2019 15:20 — forked from diegopacheco/Dockerfile
Dockerfile - Terraform + Amazon Linux
FROM amazonlinux:latest
WORKDIR /
RUN yum update -y
RUN yum group install "Development Tools" -y
RUN yum install -y git zip wget
RUN wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip && unzip terraform_0.11.7_linux_amd64.zip
RUN chmod +x terraform
COPY . .
RUN chmod +x /run.sh
CMD ["/run.sh"]
# iam_sagemaker.tf
resource "aws_iam_role" "sm_notebook_instance_role" {
name = "sm-notebook-instance-role"
...
}
resource "aws_iam_policy" "sm_notebook_instance_policy" {
name = "sm-notebook-instance-policy"
description = "Policy for the Notebook Instance to manage training jobs, models and endpoints"
...
}
resource "aws_sagemaker_notebook_instance" "basic" {
name = "FraudDetectionNotebookInstance"
role_arn = "${aws_iam_role.sm_notebook_instance_role.arn}"
instance_type = "ml.t2.medium"
lifecycle_config_name = "${aws_sagemaker_notebook_instance_lifecycle_configuration.basic_lifecycle.name}"
}
resource "aws_sagemaker_notebook_instance_lifecycle_configuration" "basic_lifecycle" {
name = "BasicNotebookInstanceLifecycleConfig"
on_start = "${base64encode(data.template_file.instance_init.rendered)}"
}