You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cloud/connect/serverless/aws-lambda.md
+34-30Lines changed: 34 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,24 @@ import PageTitle from '@site/src/components/PageTitle';
8
8
9
9
<PageTitletitle="Connecting from AWS Lambda | Dragonfly Cloud" />
10
10
11
-
AWS Lambda is a serverless compute service provided by Amazon Web Services (AWS). It allows you to run code without provisioning or managing servers. You simply upload your code, and Lambda automatically handles the execution, scaling, and availability. It supports various programming languages and integrates seamlessly with other AWS services, making it ideal for building scalable, event-driven applications.
11
+
This guide explains how to create an AWSLambda function that connects to a Dragonfly Cloud data store.
12
12
13
-
This guide explains how to create an AWS Lambda function that connects to a Dragonfly Cloud instance.
13
+
[AWS Lambda](https://aws.amazon.com/lambda/) is a serverless compute service provided by Amazon Web Services (AWS).
14
+
It allows you to run code without provisioning or managing servers.
15
+
You simply upload your code, and Lambda automatically handles the execution, scaling, and availability.
16
+
It supports various programming languages and integrates seamlessly with other AWS services,
17
+
making it ideal for building scalable, event-driven applications.
18
+
19
+
**Note**: You can skip to the [Connecting to a Private Dragonfly Data Store](#connecting-to-a-private-dragonfly-data-store)
20
+
section if you already have the Lambda function set up and just want to learn how to work with private Dragonfly Cloud data stores.
14
21
15
22
---
16
23
17
24
## Prerequisites
18
25
19
-
1.**Dragonfly Cloud Instance**: Ensure you have a running Dragonfly Cloud instance and its connection URI.
26
+
1.**Dragonfly Cloud Data Store**: Ensure you have a running [Dragonfly Cloud](https://dragonflydb.cloud/) data store and its connection URI.
20
27
2.**AWS Account**: Access to AWS Lambda and IAM services.
21
-
3.**Node Runtime**: The Lambda function will be written in NodeJS.
28
+
3.**Node Runtime**: In this guide, the Lambda function will be written in NodeJS.
22
29
4.**Redis Client Library**: Use the `redis` package to interact with Dragonfly.
23
30
24
31
---
@@ -33,21 +40,17 @@ This guide explains how to create an AWS Lambda function that connects to a Drag
33
40
4. Provide a name for your function (e.g., `DragonflyConnector`).
34
41
5. Click **Create function**.
35
42
36
-
---
37
-
38
-
### 2. Add the Dragonfly URI as an Environment Variable
43
+
### 2. Set Environment Variable(s)
39
44
40
-
1.In the Lambda function configuration, go to the **Configuration** tab.
45
+
1.Within the Lambda function, go to the **Configuration** tab.
41
46
2. Select **Environment variables**.
42
47
3. Add a new variable:
43
48
-**Key**: `DRAGONFLY_CONNECTION_URI`
44
49
-**Value**: Your Dragonfly Cloud connection URI (e.g., `rediss://<username>:<password>@<host>:<port>`).
45
50
46
-
---
47
-
48
51
### 3. Write the Lambda Function Code
49
52
50
-
Create a module Javascript file (e.g., `index.mjs`) with the following code:
53
+
Create a module JavaScript file (e.g., `index.mjs`) with the following code:
### 6. Connecting to a Private Dragonfly Data Store
130
+
## Connecting to a Private Dragonfly Data Store
132
131
133
-
Private data stores are hosted within a Virtual Private Cloud (VPC), which provides an isolated network environment. To enable your AWS Lambda function to securely connect to a private Dragonfly data store, follow these beginner-friendly steps:
132
+
Private data stores are hosted within a Virtual Private Cloud (VPC), which provides an isolated network environment.
133
+
To enable your AWS Lambda function to securely connect to a private Dragonfly Cloud data store, follow these beginner-friendly steps:
134
134
135
-
####1. Set Up VPC Peering
135
+
### 1. Set Up VPC Peering
136
136
137
137
1. Create a VPC in your AWS account within the same region as your data store.
138
138
2. Establish a peering connection between your VPC and the data store's VPC. This allows the two networks to communicate. For detailed guidance, refer to the [VPC Peering Connections documentation](../../connections.md).
139
139
140
-
####2. Adjust Security Group Rules
140
+
### 2. Adjust Security Group Rules
141
141
142
-
1. Open the [VPC Console](https://console.aws.amazon.com/vpc/) and locate the security group associated with your vpc.
143
-
2. Add an inbound rule to allow traffic from your vpc:
142
+
1. Open the [VPC Console](https://console.aws.amazon.com/vpc/) and locate the security group associated with your VPC.
143
+
2. Add an inbound rule to allow traffic from your VPC:
144
144
-**Type**: Custom TCP Rule
145
145
-**Port Range**: `6379` (Dragonfly port).
146
146
-**Source**: CIDR of the private network.
147
147
148
-
####3. Grant Lambda the Necessary Permissions
148
+
### 3. Grant Lambda Necessary Permissions
149
149
150
150
To allow Lambda to interact with your VPC, you need to update its execution role:
151
151
@@ -154,7 +154,7 @@ To allow Lambda to interact with your VPC, you need to update its execution role
154
154
3. Under **Permissions**, click the execution role name.
155
155
4. Add the **AmazonEC2FullAccess** permission to the role. This ensures Lambda can connect to your VPC.
156
156
157
-
####4. Configure Lambda to Use the VPC
157
+
### 4. Configure Lambda to Use the VPC
158
158
159
159
1. In the [AWS Lambda Console](https://console.aws.amazon.com/lambda/), select your function.
160
160
2. Go to the **Configuration** tab and choose **VPC**.
@@ -163,15 +163,19 @@ To allow Lambda to interact with your VPC, you need to update its execution role
163
163
-**Subnets**: Choose subnets with access to the data store.
164
164
-**Security Groups**: Select the security group that allows traffic to the data store.
165
165
166
-
####5. Test the Connection
166
+
### 5. Test the Connection
167
167
168
168
1. Deploy your Lambda function as described earlier.
169
169
2. Update the `DRAGONFLY_CONNECTION_URI` environment variable with the private data store's connection URL.
170
170
3. Run a test event in the Lambda Console.
171
171
4. Check the logs or query the data store to confirm the connection is successful.
172
172
173
-
By following these steps, you can securely connect your Lambda function to a private Dragonfly data store, ensuring your application remains both scalable and secure.
173
+
By following these steps, you can securely connect your Lambda function to a private Dragonfly Cloud data store, ensuring your application remains both scalable and secure.
174
+
175
+
---
174
176
175
177
## Conclusion
176
178
177
-
You have successfully created an AWS Lambda function that connects to Dragonfly Cloud, sets a test key-value pair, and verifies the connection. You can now extend this function to perform more complex operations with Dragonfly.
179
+
You have successfully created an AWS Lambda function that connects to Dragonfly Cloud,
180
+
sets a test key-value pair, and verifies the connection.
181
+
You can now extend this function to perform more complex operations with Dragonfly.
fmt.Printf("Error connecting to Dragonfly: %v\n", err)
97
+
return
98
+
}
99
+
fmt.Printf("Connected to Dragonfly: %s\n", pong)
100
+
101
+
// Perform some test operations.
102
+
err = client.Set(ctx, "test_key", name, 0).Err()
103
+
if err != nil {
104
+
fmt.Printf("Error setting key: %v\n", err)
105
+
return
106
+
}
107
+
108
+
value, err:= client.Get(ctx, "test_key").Result()
109
+
if err != nil {
110
+
fmt.Printf("Error getting key: %v\n", err)
111
+
return
112
+
}
113
+
fmt.Printf("Retrieved value: %s\n", value)
114
+
115
+
// Close the connection.
116
+
err = client.Close()
117
+
if err != nil {
118
+
fmt.Printf("Error closing connection: %v\n", err)
119
+
}
120
+
}
121
+
```
122
+
123
+
The example code requires an environment variable named `DRAGONFLY_CONNECTION_URI`.
124
+
125
+
---
126
+
127
+
## Connecting to a Public Dragonfly Data Store
128
+
129
+
### 1. Create a New Cloud Run Function
130
+
131
+
1. Go to the [Cloud Run](https://console.cloud.google.com/run) console.
132
+
2. Click **Write a function**.
133
+
3. Provide a name for your function/service (e.g., `HelloDragonfly`).
134
+
4. Choose a Go runtime version that supports your function code.
135
+
5. Expand the **Container(s)** section and add a new environment variable under the `Variables & Secrets` tab:
136
+
-**Key**: `DRAGONFLY_CONNECTION_URI`
137
+
-**Value**: Your Dragonfly Cloud connection URI (e.g., `rediss://<username>:<password>@<host>:<port>`).
138
+
6. Click **Create** to create the function.
139
+
7. Add your code or the code provided above to the inline editor and wait for the function to be deployed.
140
+
141
+
### 2. Test the Cloud Run Function
142
+
143
+
1. Click the **Test** button in the Cloud Run console.
144
+
2. Create a new test event (you can use the default template).
145
+
3. Run the test (you can use Cloud Shell for simplicity).
146
+
4. Check the logs in **Logs** to verify the connection and the key-value pair operation.
147
+
148
+
---
149
+
150
+
## Connecting to a Private Dragonfly Data Store
151
+
152
+
Private data stores are hosted within a Virtual Private Cloud (VPC), which provides
153
+
an isolated network environment. To enable your Cloud Run function to securely
154
+
connect to a private Dragonfly Cloud data store, follow these beginner-friendly steps:
155
+
156
+
### 1. Set Up VPC Peering
157
+
158
+
1. Create a VPC in your GCP account within the same region as your data store.
159
+
2. Establish a peering connection between your VPC and the data store's VPC.
160
+
This allows the two networks to communicate. For detailed guidance, refer to the [VPC Peering Connections documentation](../../connections.md).
161
+
162
+
### 2. Adjust Firewall Rules
163
+
164
+
1. Open the [VPC Network Console](https://console.cloud.google.com/networking/networks/list).
165
+
2. Select your network and open the **Firewall** settings.
166
+
3. Add an ingress rule to allow traffic from your data store VPC. Put the data store VPC CIDR range in the source IPV4 range field, and allow all ports.
167
+
168
+
### 3. Edit Cloud Run Settings
169
+
170
+
As the data store is private, you need to configure Cloud Run's network setting
171
+
to the VPC network you just created.
172
+
173
+
1. Go to the [Cloud Run](https://console.cloud.google.com/run). Select your service.
174
+
2. Navigate to the **Networking** tab.
175
+
3. Select **Internal Ingress**. Save changes.
176
+
4. Once deployed, click **Edit & deploy new version**.
177
+
5. Make sure the `DRAGONFLY_CONNECTION_URI` environment variable is set to the data store's private connection URI.
178
+
6. Go to **Networking**. Select **Connect to a VPC for outbound traffic**. Choose your VPC.
179
+
7. Deploy the changes.
180
+
181
+
### 4. Test the Connection
182
+
183
+
1. Click **Test**. Copy the test command.
184
+
2. You need to create a VM instance inside your VPC to run the test. Go to the **VM instances** tab and
185
+
create a VM instance. Make sure you've configured the network interface to use your VPC.
186
+
3. Update your firewall rules so that you can connect to the instance via SSH.
187
+
4. SSH to your machine and run the test command.
188
+
189
+
You'll see in **Logs** that Dragonfly has stored the value.
190
+
By following these steps, you can securely connect your Cloud Run service to a private Dragonfly Cloud data store,
191
+
ensuring your application remains both scalable and secure.
192
+
193
+
---
194
+
195
+
## Conclusion
196
+
197
+
You have successfully created a GCP Cloud Run function that connects to Dragonfly Cloud,
198
+
sets a test key-value pair, and verifies the connection.
199
+
You can now extend this function to perform more complex operations with Dragonfly.
Copy file name to clipboardExpand all lines: docs/cloud/connect/serverless/serverless.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -14,3 +14,4 @@ import PageTitle from '@site/src/components/PageTitle';
14
14
Dragonfly Cloud offers seamless integration with serverless services, enabling you to leverage its high-performance in-memory data store for your applications. This guide will walk you through the steps to connect your serverless environment to Dragonfly Cloud, ensuring optimal performance and compatibility. Whether you're using AWS Lambda, Google Cloud Functions, or Azure Functions, Dragonfly Cloud provides the tools and support you need to get started quickly and efficiently.
0 commit comments