Skip to content

Instantly share code, notes, and snippets.

View EngineerLabShimazu's full-sized avatar

Shimazu EngineerLabShimazu

  • self-employed
  • Japan
View GitHub Profile
@EngineerLabShimazu
EngineerLabShimazu / show_ami_version.py
Created May 28, 2020 01:26
How to show aws lambda runtime version?
import subprocess
def lambda_handler(event, context):
"""
Amazon Linux release 2 (Karoo)
runtime: python3.8
date: 2020/05/28
"""
proc = subprocess.run(['cat', '/etc/system-release'], stdout = subprocess.PIPE)
print(proc.stdout.decode("utf8"))
@EngineerLabShimazu
EngineerLabShimazu / class-commands.py
Last active January 15, 2020 15:16
Python argparse.ArgumentParser sample
import sys
import argparse
class Command:
def __init__(self, args):
parser = argparse.ArgumentParser(description='class sample')
parser.add_argument('--main', '-m', action='store_true', help='main command from class')
self.parser = parser
try:
@EngineerLabShimazu
EngineerLabShimazu / alexa-get-skill-name.py
Last active January 11, 2020 06:15
Alexa-スキル名を取得する関数
_SKILL_JSON_PATH = os.getenv('SKILL_JSON', 'skill.json')
_SKILL_NAME = os.getenv('SKILL_NAME', '')
def get_skill_name(locale: str = 'ja-JP') -> str:
"""
Priority
1. skill.json "manifest.publishingInformation.locales.{your-locale}.name"
2. environment valuable from "lambda"
3. from python
@EngineerLabShimazu
EngineerLabShimazu / amazon_athena_create_table.ddl
Last active October 26, 2022 06:36
Create a table in Athena from a csv file with header stored in S3.
CREATE EXTERNAL TABLE IF NOT EXISTS default.table
(
`id` int,
`name` string,
`timestamp` string,
`is_debug` boolean
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
'escapeChar'='\\',
@EngineerLabShimazu
EngineerLabShimazu / put_s3_from_lambda.py
Last active October 31, 2019 07:23
Put json file to S3 from Lambda
import json
import os
import boto3
import botocore
def handler(event, context):
bucket = os.environ.get('BUCKET')
key = os.environ.get('KEY')
@EngineerLabShimazu
EngineerLabShimazu / deploy_lambda.sh
Created October 30, 2019 06:08
Deploy to lambda in python3.7
#!/usr/bin/env bash
LAMBDA_NAME="your-lambda-name"
cd venv/lib/python3.7/site-packages
zip -r9 ${OLDPWD}/function.zip .
cd ${OLDPWD}
cd ./lambda/custom/
zip -g ../../function.zip your_function.py
cd ${OLDPWD}
aws lambda update-function-code \
--function-name ${LAMBDA_NAME} \
@EngineerLabShimazu
EngineerLabShimazu / s3_uploader.sh
Created October 18, 2019 01:22
Schedule upload to S3
#!/bin/bash
# $ crontab -l
# * 23 * * * bash /path/to/s3_uploader.sh
# $ which aws
# /usr/local/bin/aws
# Add path to aws cli
PATH=$PATH:/usr/local/bin