LoginSignup
3
1

More than 1 year has passed since last update.

AWS Lambda から Amazon Document DB に接続した

Posted at

VPC を作成

image.png

セキュリティグループを作成

ec2

image.png

document-db

image.png

サブネットグループの作成

image.png

document db 作成

image.png

image.png

ec2 を作成

image.png

image.png

ec2 に mongo シェルをインストール

接続

connecting to: mongodb://docdb-xxxxxxxxxxx.docdb.amazonaws.com:27017/?gssapiServiceName=mongodb
2022-06-28T00:14:02.722+0000 W NETWORK  [thread1] Failed to connect to 10.0.150.226:27017 after 5000ms milliseconds, giving up.
2022-06-28T00:14:02.722+0000 E QUERY    [thread1] Error: couldn't connect to server docdb-2022-06-27-22-46-04.cluster-c9htjlshc7qa.ap-northeast-1.docdb.amazonaws.com:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:275:13
@(connect):1:6
exception: connect failed

セキュリティグループの設定がおかしかったことが原因

image.png

document db にあてているセキュリティーグループのインバウンドルールのポートを修正した

image.png

Lambda を API で叩く

Lambda から Document DB に接続

TLS が有効な場合と無効な場合の接続方法が公式ドキュメントにあった

TLS が有効な場合、うまく接続できなかったのでとりあえず、無効にした

Lambda の VPC を設定

image.png

3
1
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
3
1