https://s3.amazonaws.com/quickstart-reference/mongodb/latest/doc/MongoDB_on_the_AWS_Cloud.pdf
- 選 new VPC
- 會到 cloudformation
- 下一步
- Availability Zones <=要全選
- Number of Availability Zones <=全部
- Allowed Bastion External Access CIDR Allowed CIDR <= 0.0.0.0/0
- Key Pair Name <= key選本機原有的就好了<=之後還要從本機copy到,他開的機器,做ssh 的測試。
- MongoDB Admin Username ...
- MongoDB Admin Password ...
- 下一步
- 約20分鐘
- 會開出兩台 ec2
- LinuxBastion <= 測試你的 mongo cluster 用的
- PrimaryReplicaNode0 <= mongo cluster 只有 vpc 能連
- pdf 的測試方式為
- scp -i key .... 到 LinuxBastion
scp –i mykey.pem mykey.pem ec2-user@Bastion-public-ip:/home/ec2-user/mykey.pem
- ssh - i key PrimaryReplicaNode0的ip
- mongo
mongouse admindb.auth("admin", "YourAdminPassword") rs.printReplicationInfo()rs.status()
- 應該都正常了
===lambda
- 我直接改這個範例做測試
https://github.com/serverless/examples/tree/master/aws-node-rest-api-mongodb
service: aws-node-rest-api-mongodbprovider:name: awsregion: ap-northeast-1 //記得region 要設對,不然找不到 sgruntime: nodejs6.10vpc:securityGroupIds:- "sg-db38a1xx" //加這個subnetIds:- "subnet-39dd6bxx" //加這個- "subnet-44e59exx" //加這個functions:createUser:handler: handler.createUserevents:- http:path: usermethod: postcors: truevpc:securityGroupIds:- "sg-db38a1xx" //加這個subnetIds:- "subnet-39dd6bxx" //加這個- "subnet-44e59exx" //加這個- securityGroupIds <= 來自ec2 => PrimaryReplicaNode0 => Security groups
=> 點進去 => 看 Source - Subnet ID <= 來自ec2 => PrimaryReplicaNode0 => Subnet ID
- sls deploy
endpoints:
POST - https:// x.execute-api.ap-northeast-1.amazonaws.com/dev/user
PUT - https://x.execute-api.ap-northeast-1.amazonaws.com/dev/user/{id}
DELETE - https://x.execute-api.ap-northeast-1.amazonaws.com/dev/user/{id}
GET - https://x.execute-api.ap-northeast-1.amazonaws.com/dev/user/{id}
照這個試試吧!
結束!