Introduction
Scenario
In FunctionGraph, different function instances do not share states. Databases can persistently store structured data, which achieves state sharing. FunctionGraph can be used to access cloud databases to query and insert data.
This section describes how to access RDS for MySQL from FunctionGraph and query data, and provides sample code for testing. The sample uses a database connection pool and retry mechanism to improve performance and reliability, demonstrating a secure and efficient way to work with RDS for MySQL in FunctionGraph.
Resource and Cost Planning
Table 1 describes the resources required for the practice of accessing RDS for MySQL from FunctionGraph.
Resource |
Description |
Billing |
---|---|---|
FunctionGraph |
|
|
RDS |
|
|
VPC |
|
|
Procedure
This following describes the procedure for using a FunctionGraph function to access RDS for MySQL. For details, see Procedure.
Step |
Description |
---|---|
Before starting this practice, ensure you have a VPC network environment, an RDS for MySQL instance with its database and tables, and a function agency with VPC Administrator permission already created. |
|
In this practice, Python sample code is used to implement database connection and access. The code depends on the pymysql and DBUtils packages, which must be uploaded to the FunctionGraph console for subsequent invocations. |
|
On the FunctionGraph console, create a function for accessing RDS for MySQL. |
|
On the function details page, configure the function code, dependencies, and function settings. |
|
Test whether the function can access records in the database table of the RDS for MySQL instance. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot