LoginSignup
68
63

More than 3 years have passed since last update.

[localstack] ローカル環境にAWSサービスのモックを作り開発をする

Last updated at Posted at 2017-08-03

AtlassianのLocalStackを使ってみてなんとなく理解するまでのお話 の通りなのですが本家のgithubを見るとこんな感じになってたので現行どうするかを備忘録としてメモします。

 
 スクリーンショット 2017-08-02 16.33.49.png

Atlassian/localstack -> localstack/localstack に変更になってます。

前提

  • Mac(macOS Sierra)
  • Docker Commnity Edition (Version: 7.06.0-ce-mac19)

  • dockerコマンドがコンソール上で実行可能であること

  • AWS CLIの設定が完了していること

イメージの準備

pull
docker pull localstack/localstack

起動

run
docker run -it -p 4567-4582:4567-4582 -p 8080:8080 localstack/localstack

起動させたらコンソールは放置

確認

ブラウザを立ち上げ

http://localhost:8080/

へアクセス

こんな画面が立ち上がってれば安心して大丈夫

エンドポイント

githubから転記してきましたが、変わってる可能性があるので必ず本家で確認して下さい。
https://github.com/localstack/localstack

サービス名 エンドポイントURL
API Gateway http://localhost:4567
Kinesis http://localhost:4568
DynamoDB http://localhost:4569
DynamoDB Streams http://localhost:4570
Elasticsearch http://localhost:4571
S3 http://localhost:4572
Firehose http://localhost:4573
Lambda http://localhost:4574
SNS http://localhost:4575
SQS http://localhost:4576
Redshift http://localhost:4577
ES (Elasticsearch Service) http://localhost:4578
SES http://localhost:4579
Route53 http://localhost:4580
CloudFormation http://localhost:4581
CloudWatch http://localhost:4582

AWS CLI

CLIコマンドを発行する場合
--endpoint-url で上記のエンドポイントを指定して使用します。
デフォルトのリージョンをconfigで指定していない場合、コマンドで--region を指定する必要があります。

サンプル(SQS)
aws sqs create-queue \
        --queue-name 'SAMPLE' \
        --region ap-northeast-1 \
        --endpoint-url http://localhost:4576 \
        --profile $myProfile

SDK(nodejs)

サンプル
'use strict';

const AWS = require('aws-sdk');
const endPoint = new AWS.Endpoint('http://localhost:4578');
const region = 'ap-northeast-1';
const s3 = new AWS.S3({ endpoint: endPoint, region: region });

基本的にはエンドポイントに上記URLを指定するだけでAPIをリクエストすることが出来ます。
ElasticSearchはすでに使用可能な状態のElasticSearchが動いています。ESの方はドメイン作成とかのAPI用のモックって感じですね。
開発の際に特にデータ系は何かレスポンスが必要なので地味に使えるツールですね

68
63
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
68
63