オプション | 説明 | 使用例 |
--region | リージョン | --region ap-northeast-1 |
--endpoint-url | エンドポイント ※DynamoDB Local 等にコマンド発行する場合に利用 | --endpoint-url http://localhost:8000 |
--output | 実行結果の出力形式 | --output json |
--profile | 使用するプロファイル名 | --profile developper |
※http://docs.aws.amazon.com/cli/latest/reference/
aws configure --profile developper AWS Access Key ID [None]: XXXXXXXXXXXXXXX AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXX Default region name [None]: ap-northeast-1 Default output format [None]: json
※事前に I AM から ユーザとアクセスキーを作成しておく。
aws sts get-caller-identity | grep Account | awk '{print $2}' | sed -e "s/[^0-9]//g"
mkdir test-function cd test-function vim index.js # Lambda関数を入力 zip -r test-function.zip . aws lambda create-function \ --function-name test-function \ --runtime nodejs6.10 \ --role arn:aws:iam::xxxxxxxxxxxx:role/xxxxxxxx \ --handler index.handler \ --zip-file fileb://test-function.zip
rm -rf test-function.zip && \ zip -r test-function.zip . && \ aws lambda update-function-code --function-name test-function --zip-file fileb://test-function.zip
aws lambda delete-function \ --function-name test-function \ --region ap-northeast-1 \ --profile developper
aws lambda invoke \ --invocation-type RequestResponse \ --function-name helloworld \ --region ap-northeast-1 \ --log-type Tail \ --payload '{"key1":"value1", "key2":"value2", "key3":"value3"}' \ --profile developper \ outputfile.txt
http://docs.aws.amazon.com/cli/latest/reference/dynamodb/index.html
aws dynamodb list-tables
aws dynamodb create-table \ --profile developper \ --table-name Books \ --attribute-definitions \ AttributeName=id,AttributeType=S \ AttributeName=isbn,AttributeType=S \ AttributeName=title,AttributeType=S \ --key-schema AttributeName=id,KeyType=HASH AttributeName=isbn,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 \ --global-secondary-indexes IndexName=title-index,KeySchema=[{AttributeName=title,KeyType=RANGE}],Projection={ProjectionType=KEYS_ONLY},ProvisionedThroughput={ReadCapacityUnits=1,WriteCapacityUnits=1}
※ --endpoint-url http://localhost:8000 をつければ ローカルの DynamoDB も作れる。
もしくは DDL的なものを作ってから作成する場合は
DDL( books.json ) を作成
{ "TableName": "Books", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" }, { "AttributeName": "isbn", "AttributeType": "S" }, { "AttributeName": "title", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "id", "KeyType": "HASH" } ], "ProvisionedThroughput": { "WriteCapacityUnits": 1, "ReadCapacityUnits": 1 }, "GlobalSecondaryIndexes": [ { "IndexName": "isbn-index", "KeySchema": [ { "AttributeName":"isbn", "KeyType":"HASH" } ], "Projection": {"ProjectionType": "KEYS_ONLY" }, "ProvisionedThroughput": {"ReadCapacityUnits": 1,"WriteCapacityUnits": 1 } }, { "IndexName": "title-index", "KeySchema": [ { "AttributeName":"title", "KeyType":"HASH" } ], "Projection": {"ProjectionType": "KEYS_ONLY" }, "ProvisionedThroughput": {"ReadCapacityUnits": 1,"WriteCapacityUnits": 1 } } ] }
DDLを使用してテーブル作成
aws dynamodb create-table --cli-input-json file://books.json
aws dynamodb delete-table --table-name Books
aws dynamodb scan --table-name Books
aws dynamodb query --endpoint-url http://localhost:8000 --table-name ExampleTable \ --key-condition-expression ' key1 = :key1 AND key2 = :key2' \ --expression-attribute-values '{ ":key1": {"S":"A"}, ":key2": {"S":"01"} }'
aws dynamodb query --endpoint-url http://localhost:8000 --table-name ExampleTable \ --index-name gsicol1-index \ --key-condition-expression 'gsiCol1 = :gsiCol1' \ --expression-attribute-values '{ ":gsiCol1": {"S":"A01-01"} }'
※取得できるのは、射影されているデータのみ
aws dynamodb put-item --endpoint-url http://localhost:8000 --table-name ExampleTable \ --item '{ "key1" : { "S" : "A"}, "key2" : { "S" : "01"}, "col1" : { "S" : "value1"}, "col2" : { "S" : "value2"} }'
aws dynamodb update-item --endpoint-url http://localhost:8000 --table-name ExampleTable \ --key '{ "key1": {"S":"A"}, "key2": {"S":"01"} }' \ --update-expression 'SET col1 = :col1' \ --expression-attribute-values '{ ":col1": {"S":"value1-update!"} }'
尚、主キー項目の値変更はできない模様。
An error occurred (ValidationException) when calling the UpdateItem operation: This attribute is part of the key と怒られる。
aws dynamodb delete-item --endpoint-url http://localhost:8000 --table-name ExampleTable \ --table-name ExampleTable \ --key '{ "key1": {"S":"A"}, "key2": {"S":"01"} }'
https://docs.aws.amazon.com/cli/latest/reference/kinesis/index.html
aws kinesis create-stream --stream-name Foo --shard-count 1
aws kinesis put-record --stream-name Foo --partition-key 123 --data testdata
aws kinesis get-shard-iterator --shard-id shardId-000000000000 --shard-iterator-type TRIM_HORIZON --stream-name Foo
aws kinesis delete-stream --stream-name Foo
https://docs.aws.amazon.com/cli/latest/reference/s3api/
https://docs.aws.amazon.com/cli/latest/reference/s3/
aws s3api list-buckets --output text
aws s3api list-objects --bucket バケット名 --output text
aws s3api get-object --bucket バケット名 --key キー名 出力先ファイルPATH
aws s3api put-object --bucket バケット名 --key キー名 --body アップロードするファイルのPATH
https://docs.aws.amazon.com/cli/latest/reference/ssm/index.html#cli-aws-ssm
aws ssm put-parameter --name パラメータ名 --value 値 --type [String|StringList|SecureString] --description "説明" --overwrite
aws ssm get-parameter --name パラメータ名