How do I use DynamoDB Accelerator (DAX) with AWS Lambda?
3 minute read
I want to use my Amazon DynamoDB Accelerator (DAX) cluster with my AWS Lambda function. How do I do that?
After you create a DAX cluster, note the VPC ID, subnets, and security group launched with the DAX cluster. Keep this information available for reference. Then, follow the steps below to use your Lambda function with your DAX cluster.
Create a Lambda function with access to your DAX cluster's VPC
2. Choose Create function, and then enter a Function name.
3. Choose the Runtime and Architecture under Basic information.
4. Expand Advanced settings. Then, check the box to the left of Enable VPC.
5. In the VPC dropdown list, choose the previously noted VPC. This is the VPC in which your DAX Cluster was launched.
6. In the Subnets dropdown list, choose the previously noted subnets. Select all that apply.
7. In the Security group dropdown list, choose the previously noted VPC security group. The console shows the inbound and outbound rules for that security group.
Important: For the Lambda function to connect with the DAX Cluster, the Inbound rules for the security group must display TCP as the Protocol. Also, 8111 or 9111 must appear under Ports. 8111is for unencrypted clusters, and 9111 is for encrypted clusters.
8. Choose Create function.
Configure an existing Lambda function to access your DAX cluster's VPC
2. Choose the function that you want to use with your DAX Cluster.
3. Choose Configuration from the ribbon, and then choose VPC. Choose Edit.
4. Follow steps 4 through 6 in the previous section, Create a Lambda function with access to your DAX cluster's VPC.
5. Choose Save.
Test the connection from your Lambda function to your DAX cluster
Important: You must first prepare a deployment package because amazondax isn't available by default in Lambda. See the All versions section in Amazon DynamoDB Accelerator (DAX) to install amazon-dax-client.