AWS Cognito
您可以直接从 Supabase 控制面板启用AWS Cognito包装器。
在控制面板中打开包装器AWS Cognito 是用于 Web 和移动应用程序的身份平台。
Cognito 包装器允许您在 Postgres 数据库中读取 Cognito 用户池中的数据。
准备#
在您能够查询 AWS Cognito 之前,您需要启用 Wrappers 扩展并在 Postgres 中存储您的凭据。
启用 Wrappers#
确保 wrappers 扩展已安装在您的数据库上
1create extension if not exists wrappers with schema extensions;启用 Cognito 包装器#
启用 cognito_wrapper FDW
1create foreign data wrapper cognito_wrapper2 handler cognito_fdw_handler3 validator cognito_fdw_validator;存储您的凭据(可选)#
默认情况下,Postgres 将 FDW 凭据以明文形式存储在 pg_catalog.pg_foreign_server 中。任何访问此表的人都将能够查看这些凭据。Wrappers 设计为与 Vault 配合使用,Vault 为存储凭据提供了额外的安全级别。我们建议使用 Vault 存储您的凭据。
1-- Save your Cognito secret access key in Vault and retrieve the created `key_id`2select vault.create_secret(3 '<secret access key>',4 'cognito',5 'Cognito secret key for Wrappers'6);连接到 Cognito#
我们需要向 Postgres 提供连接到 Cognito 的凭据以及任何其他选项。我们可以使用 create server 命令来执行此操作
1create server cognito_server2 foreign data wrapper cognito_wrapper3 options (4 aws_access_key_id '<your_access_key>',5 api_key_id '<your_secret_key_id_in_vault>',6 region '<your_aws_region>',7 user_pool_id '<your_user_pool_id>'8 );创建模式#
我们建议创建一个模式来保存所有外部表
1create schema if not exists cognito;实体#
我们可以使用 SQL import foreign schema 从 Cognito 导入外部表定义。
例如,使用下面的 SQL 可以自动在 cognito 模式中创建外部表。
1import foreign schema cognito from server cognito_server into cognito;外部表将如下所示创建
用户#
这是一个代表 Cognito 用户记录的对象。
操作#
| 对象 | 选择 | 插入 | 更新 | 删除 | 截断 |
|---|---|---|---|---|---|
| 用户 | ✅ | ❌ | ❌ | ❌ | ❌ |
用法#
1create foreign table cognito.users (2 username text,3 email text,4 status text,5 enabled boolean,6 created_at timestamp,7 updated_at timestamp,8 attributes jsonb9)10server cognito_server11options (12 object 'users'13);说明#
- 外部表中仅接受上述列
attributes列包含 JSON 格式的附加用户属性
查询下推支持#
此 FDW 不支持查询下推。
限制#
本节描述了在使用此 FDW 时需要注意的重要限制和注意事项
- 不支持查询下推,所有过滤必须在本地完成
- 由于需要完全的数据传输,大型结果集可能会遇到较慢的性能
- 仅支持来自 Cognito API 的用户池对象
- 不支持身份池操作
- 使用这些外部表的物化视图在逻辑备份期间可能会失败
示例#
基本示例#
这将会在您的 Postgres 数据库中创建一个名为 cognito_table 的“外部表”
1create foreign table cognito.users (2 username text,3 email text,4 status text,5 enabled boolean,6 created_at timestamp,7 updated_at timestamp,8 attributes jsonb9)10server cognito_server11options (12 object 'users'13);现在您可以从 Postgres 数据库中获取您的 Cognito 数据
1select * from cognito.users;