pandazx's blog

データ分析など雑多な技術ブログ

AWS SDKサンプルプログラム(Python2)

Get S3 bucket list

# coding:utf-8

from boto3.session import Session
import os

session = Session(
    aws_access_key_id = os.environ['access_key'],
    aws_secret_access_key = os.environ['secret_access_key'],
    region_name = 'ap-northeast-1',
)

s3 = session.resource('s3')
for bucket in s3.buckets.all():
    print(bucket.name)

Get kinesis shard IDs

# coding:utf-8

import boto3
import os

# Get stream info
client = boto3.client('kinesis')
shard = client.describe_stream(StreamName = os.environ['kinesis_stream_name'])
for x in shard['StreamDescription']['Shards']:
    print(x['ShardId'])