Skip to content

Instantly share code, notes, and snippets.

@shiro01
shiro01 / db_access_by_lambda.py
Last active June 28, 2018 06:09
db_access_by_lambda.py
# $ python3 -m venv env
# $ source env/bin/activate
# $ mkdir mysql_test;cd mysql_test
# $ pip install mysqlclient -t ./
# mysqlclient is needs "gcc, python-devel, libmysqlclient-devel"
# $ vi lambda_function.py
# $ zip -r9 lambda_mysql.zip .
# zipfile upload to aws.
# It may be necessary to set up vpc or subnet
@shiro01
shiro01 / lambda_test_env_url_cmd.py
Last active May 21, 2018 07:24
lambda test. env, url, cmd
import json
import os
import urllib.request
import subprocess
def lambda_handler(event, context):
test = test_event_param(event)
#submit_url()
#cmd_exec()
@shiro01
shiro01 / lambda_s3_bucket_contents_list.py
Last active May 21, 2018 07:05
s3_bucket_contents_list
import boto3
def lambda_handler(event, context):
AWS_S3_BUCKET_NAME = 'bucket_name'
s3_resource = boto3.resource('s3')
bucket = s3_resource.Bucket(AWS_S3_BUCKET_NAME)
result = bucket.meta.client.list_objects_v2(Bucket=bucket.name, Prefix='bucket_dir')
files = [o.get('Key') for o in result.get('Contents') if not o.get('Key').endswith('/')]
print(files)
return files
@shiro01
shiro01 / apigateway_resource_policie.json
Last active October 17, 2018 00:51
APIGateway_Resource_Policie. Allow IP.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:ap-northeast-1:*:*/test_stage/POST/*",
"Condition": {
"IpAddress": {
@shiro01
shiro01 / nodejs-split-string.js
Last active May 23, 2018 04:40
Split string with nodejs
function splitString (targetString,separator1,separator2) {
console.log('TargetString: "' + targetString + '"');
console.log('Separator1: "' + separator1 + '"');
console.log('Separator1: "' + separator2 + '"');
var arrayOfStrings = targetString.split(separator1);
var tmpMap = new Map();
//for (var i = 0; i < arrayOfStrings.length; i++) {
// var splitBycolon = arrayOfStrings[i].split(separator2);
@shiro01
shiro01 / fetch_call_api_test.html
Created May 30, 2018 06:24
API call made with APIGateway from HTML with fetch.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>fetch_api</title>
</head>
<body>
<input type="button" value="GET" onclick=submitGetApi()>
<div id="getResult"></div>
@shiro01
shiro01 / datetimeFormatValidation.js
Last active June 5, 2018 06:01
datetime format validation.
datetimeStart = "2018-01-01 00:00:00";
datetimeEnd = "2018-01-01 23:59:59";
function validation(datetimeStart, datetimeEnd) {
if (!/^\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}$/.test(datetimeStart)) {
return false;
} else if (!/^\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2}$/.test(datetimeEnd)) {
return false;
} else if (datetimeStart >= datetimeEnd) { // 0埋めの場合、文字列のまま比較可能
return false;
@shiro01
shiro01 / OptionalTest.java
Created June 8, 2018 03:56
Optionalクラスを試してみる。
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class OptionalTest {
public static void main(String[] args) {
@shiro01
shiro01 / dict_to_csv.py
Last active June 13, 2018 05:03
dict data save to csv file
import csv
data = [
{
"deta1":"111"
,"data2":"222"
},
{
"deta1":"333"
,"data2":"444"
@shiro01
shiro01 / save_to_s3_bucket.py
Created June 13, 2018 05:08
save file to s3 bucket
file_name = 'test.txt'
bucket_name= 'bucket-name'
bucket_dir = 'bucket-dir'
file_path = '/tmp/' + file_name
key = bucket_dir + file_name
s3bucket = boto3.resource('s3').Bucket(bucket_name)
s3bucket.upload_file(file_path, key)