This repository demonstrates how a Lambda Function needs to be configured to save items in MongoDB. To connect to the MongoDB cluster vpc-peering is used.
- Python3 installed, version > 3.6
- aws cli installed: instructions
- sam cli installed: instructions
You need to update certain config values in this project to make it work for your own vpc!
In template.yaml
:
- update the environment variable that specifies the connection string, database and collection to your own connection string, database and connection.
Environment: Variables: MONGODB_CONNECTION_STRING: mongodb+srv://<user>:<password>@<your-cluster>.mongodb.net/test?retryWrites=true&w=majority DATABASE: yourDatabaseName COLLECTION: yourCollectionName
- update the
VpcConfig
with your own vpc security group and subnet:VpcConfig: SecurityGroupIds: - sg-08b12e8bdf431b849 SubnetIds: - subnet-08a19d1a47914c5ac
From the root directory run ./deploy.sh
This will:
- install the needed dependencies
- zip your code
- deploy the lambda function
Answer y
on the input that is asked.
When you have deployed successfully you could change the last line of the script sam deploy --guided
to sam deploy
.