Skip to content

Instantly share code, notes, and snippets.

View DaisukeMiyamoto's full-sized avatar

Daisuke Miyamoto DaisukeMiyamoto

  • Tokyo, Japan
View GitHub Profile
@DaisukeMiyamoto
DaisukeMiyamoto / deploy_redshift.sh
Last active December 31, 2021 03:25
CloudFormation template for Redshift and SageMaker in a private subnet in a VPC
#!/bin/bash -xeu
STACK_NAME=VPC-Redshift
TEMPLATE_BUCKET=SET_YOUR_TEMPLATE_BUCKET_NAME
REGION=us-east-2
DATABASE_NAME=SET_YOUR_DATABASE_NAME
MASTER_USER_PASSWORD=$(mkpasswd -l 12 -s 0)
# upload files
@DaisukeMiyamoto
DaisukeMiyamoto / cloudtrail.yaml
Last active October 9, 2018 00:47
CloudFormation template for CloudTrail with KMS and S3 bucket
---
AWSTemplateFormatVersion: "2010-09-09"
Description: |
CloudTrail: v0.1.0 -
CloudTrail Trail, related S3 bucket, and KMS Key for encryption
Parameters:
@DaisukeMiyamoto
DaisukeMiyamoto / assume_role.py
Created September 12, 2018 05:00
AWS Boto3 Assume Role example
import boto3
from boto3.session import Session
def assume_role(arn, session_name):
"""aws sts assume-role --role-arn arn:aws:iam::00000000000000:role/example-role --role-session-name example-role"""
client = boto3.client('sts')
account_id = client.get_caller_identity()["Account"]
print(account_id)
@DaisukeMiyamoto
DaisukeMiyamoto / index.html
Created August 15, 2018 03:50
AWS IoT pub/sub example
<html lang="ja">
<body>
<div>
<input type="text" name="say" id="say" placeholder="Input a message here...">
<button id="send">Send</button>
</div>
<ul id="chat">
<li v-for="m in messages">{{ m }}</li>
</ul>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<!--<link rel="icon" href="../../../../favicon.ico">-->
import boto3
bucket_name = ''
name_list = [
]
def register(name):
s3 = boto3.client('s3')
s3.upload_file(
@DaisukeMiyamoto
DaisukeMiyamoto / lex-lambda-hello.py
Last active July 26, 2018 02:22
hello from lex in AWS Lambda
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def dispatch(intent_request):
logger.debug('dispatch userId={}, intentName={}'.format(intent_request['userId'], intent_request['currentIntent']['name']))
intent_name = intent_request['currentIntent']['name']
@DaisukeMiyamoto
DaisukeMiyamoto / example-polly.py
Created July 24, 2018 06:34
polly example in japanese (日本語)
import boto3
from contextlib import closing
polly = boto3.client('polly')
text = '吾輩は猫である。名前はまだ無い。どこで生れたかとんと見当がつかぬ。何でも薄暗いじめじめした所でニャーニャー泣いていた事だけは記憶している。吾輩はここで始めて人間というものを見た。しかもあとで聞くとそれは書生という人間中で一番獰悪な種族であったそうだ。この書生というのは時々我々を捕えて煮て食うという話である。しかしその当時は何という考もなかったから別段恐しいとも思わなかった。'
voice = 'Mizuki'
filename = 'sample.mp3'
@DaisukeMiyamoto
DaisukeMiyamoto / locust-kinesis.py
Created June 19, 2018 02:14
benchmark for AWS Kinesis Data Stream
# -*- coding: utf-8 -*-
import time
import datetime
import boto3
from locust import HttpLocust, TaskSet, task
from locust.events import request_success
class UserBehavior(TaskSet):
@DaisukeMiyamoto
DaisukeMiyamoto / kinesis-twitter.py
Last active October 15, 2019 20:59
put twitter search results to Amazon Kinesis on AWS
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import time
import json
import twitter
import boto3