LoginSignup
6
6

More than 5 years have passed since last update.

[JAWS-UG CLI] Kinesis:#1 ストリームの作成

Last updated at Posted at 2015-06-18

注意事項

Amazon Kinesis に無料枠はありません。今回のハンズオンでは2つの shard を 2時間弱使用するため、利用料金として10円程度発生しますのでご注意ください。ハンズオン後はストリームの削除をお忘れなくお願いします。

Kinesis の料金 (2015年5月4日現在)
http://aws.amazon.com/jp/kinesis/pricing/

  • $0.0195 /h (1shardあたり)
  • $0.0430 /1,000,000 PutRecords

前提条件

Kinesis への権限

  • Kinesis に対してフル権限があること。

AWS CLI のバージョン

  • 以下のバージョンで動作確認済
    • AWS CLI 1.7.24
コマンド
aws --version
結果(例)
aws-cli/1.7.25 Python/2.7.6 Darwin/14.3.0

0. 準備

0.1. リージョンの決定

作成するストリームのリージョンを決めます。
(カレントユーザが利用するカレントリージョンも切り変わります。)

コマンド(東京リージョンの場合)
export AWS_DEFAULT_REGION='ap-northeast-1'

0.2. 変数の確認

プロファイルとリージョンが想定のものになっていることを確認します。

変数の確認
aws configure list
結果(例)
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile KinesisFull-handsOn-Kinesis-user-5KVYHRGZMYWG              env    AWS_DEFAULT_PROFILE
access_key     ****************HORA shared-credentials-file    
secret_key     ****************F9zU shared-credentials-file    
    region           ap-northeast-1              env    AWS_DEFAULT_REGION

1. 事前作業

1.1. ストリーム名の決定

ストリーム名を決めます。

command
STREAM_NAME="handson"

1.2. Shard 数の決定

シャード数をきめます。
(補足) 1Shardの容量

  • 入力 : 1MB/sec, 1000TPS
  • 出力 : 2MB/sec, 0005TPS
command
SHRD_COUNT=1

1.3 同名のストリーム名の不存在確認

command
aws kinesis describe-stream --stream-name ${STREAM_NAME}
result
A client error (ResourceNotFoundException) occurred when calling the DescribeStream operation: Stream handson under account XXXXXXXXXXXX not found.

2. ストリームの作成

2.1 ストリームの作成

command
cat << ETX

STREAM_NAME : ${STREAM_NAME}
SHARD_COUNT : ${SHRD_COUNT}

ETX
command
aws kinesis create-stream --stream-name ${STREAM_NAME} --shard-count ${SHRD_COUNT}
result
(戻り値なし)

2.2 ストリームの確認

ストリームが作成されたことを確認します。

command
aws kinesis describe-stream --stream-name ${STREAM_NAME}

ストリーム作成直後は "StreamStatus" が "CREATING" となります。

result
{
    "StreamDescription": {
        "StreamStatus": "CREATING", 
        "StreamName": "handson", 
        "StreamARN": "arn:aws:kinesis:ap-northeast-1:XXXXXXXXXXXX:stream/handson", 
        "Shards": []
    }
}

ストリームが作成されるまで、wait コマンドを実行し待ちます。
作成されると、プロンプトが戻ってきます。

command
aws kinesis wait stream-exists --stream-name ${STREAM_NAME}
result
(戻り値なし)

実際にストーリームが作成されたことを確認します。"StreamStatus" が "ACTIVE" になっていれば作成完了です

command
aws kinesis describe-stream --stream-name ${STREAM_NAME}
result
{
    "StreamDescription": {
        "StreamStatus": "ACTIVE", 
        "StreamName": "handson", 
        "StreamARN": "arn:aws:kinesis:ap-northeast-1:XXXXXXXXXXXX:stream/handson", 
        "Shards": [
            {
                "ShardId": "shardId-000000000000", 
                "HashKeyRange": {
                    "EndingHashKey": "340282366920938463463374607431768211455", 
                    "StartingHashKey": "0"
                }, 
                "SequenceNumberRange": {
                    "StartingSequenceNumber": "49550864092651309338540168505480986788282674130572017666"
                }
            }
        ]
    }
}

完了

ストリームを作成したら、次にシンプルなデータの送信/受信を行ってみます
http://qiita.com/daikumatan/items/e92d9e71f9a729ea8467

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6