简体   繁体   English

如何将 AWS Lambda 与多个 RDS 模式连接

[英]How to connect AWS Lambda with multiple RDS schemas

Hi I have a question while using AWS Lambda <-> AWS RDS.您好,我在使用 AWS Lambda <-> AWS RDS 时遇到问题。 Now I have a connection with one lambda function and one RDS db schema.现在我与一个 lambda function 和一个 RDS 数据库模式建立了连接。 In the Lambda function, I have config.py with this json codes.在 Lambda function 中,我有带有 json 代码的 config.py。

dbinfo = {
   'db' = ~
   'user' = ~
   'passwd'= ~
   'schema' = ~
}

Lambda function works for connecting in to the RDS schema, and calling store procedure. Lambda function 用于连接到 RDS 架构并调用存储过程。

Right now, there is only one schema that I have to connect with Lambda function. But soon that schema will be changed to a sharding structure.现在,我只有一个模式必须与 Lambda function 连接。但很快该模式将更改为分片结构。 (ex. game1 schema -> game1, game2 schemas) (例如游戏 1 架构 -> 游戏 1、游戏 2 架构)

That stored procedure will be stored at both schemas (game1, game2).该存储过程将存储在两个模式(游戏 1、游戏 2)中。

How to connect two schemas in one Lambda function?如何在一个 Lambda function 中连接两个模式?

Structure your config.py file something like:将您的config.py文件结构化为:

dbinfo = {
  'shard1' = {
    'db' = ~
    'user' = ~
    'passwd'= ~
    'schema' = ~
  },
  'shard2' = {
    'db' = ~
    'user' = ~
    'passwd'= ~
    'schema' = ~
  },
}

and inside of your Lambda, create multiple RDS clients for each shard.在您的 Lambda 内部,为每个分片创建多个 RDS 客户端。

And FWIW, you might want to consider storing your password outside of code in AWS ParameterStore. FWIW,您可能需要考虑将您的密码存储在 AWS ParameterStore 中的代码之外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM