英文:
Create cognito sync trigger to lambda function using Terraform
问题
我们拥有身份池,已配置事件触发器以在移动用户同步事件时触发Lambda。现在,我们计划使用Terraform重新创建基础架构以便自动化处理事务,但在设置Cognito同步触发器时遇到了困难。
我们尝试使用aws_lambda_permission
,将source_arn
指向身份池,但触发器仍然未创建,显示部分配置缺失(在Web控制台中可见)。我们无法从aws_cognito_identity_pool
资源的文档中找到用于配置身份池事件的Terraform配置。我们知道AWS建议使用Appsync来代替Cognito同步,但这是很久以前开发的,我们暂时不打算迁移。
英文:
We have identity pools which have event triggers configured to trigger lambda upon sync event from mobile users. Now that we are planning on re-creating the infrastructure using terraform so we can automate stuff, we are facing difficulties in setting up the cognito sync trigger.
We have attempted to use the aws_lambda_permission with source_arn pointing to the identity pool but still the trigger is created which shows that part of the configuration is missing (seen in web console). We are not able to identify the terraform configuration from the documentation for aws_cognito_identity_pool resource which can configure the event for identity pool. We are aware that AWS recommends Appsync in place of cognito sync but this was developed long back and we are not in the idea of migrating any sooner.
答案1
得分: 1
那个功能需要在CognitoSync客户端上调用SetCognitoEvents
方法。在搜索AWS Terraform提供程序源代码时,我找不到它的任何位置。我也没有在AWS Terraform提供程序文档中看到任何关于可以从Terraform配置此功能的信息。
我必须得出结论,目前您不能使用Terraform配置此功能,而且由于这是一个不推荐使用的功能,我怀疑Terraform将来也不会为其添加支持。
您最好的选择可能是使用null提供程序来调用AWS CLI命令aws cognito-sync set-cognito-events
。
英文:
That functionality requires a call to the SetCognitoEvents
method on the CognitoSync client. Searching through the AWS Terraform Provider source code, I can't find that anywhere. I also don't see anything in the AWS Terraform Provider documentation that would indicate you can configure this feature from Terraform.
I have to conclude that at this time you cannot configure this feature using Terraform, and since it is a deprecated feature I doubt Terraform will ever add support for it.
Your best bet may be to use a null provider to call the AWS CLI command aws cognito-sync set-cognito-events
.
答案2
得分: 0
你可以使用 aws_lambda_event_source_mapping
来实现这个功能:
resource "aws_lambda_event_source_mapping" "example" {
event_source_arn = aws_cognito_identity_pool.main.arn
function_name = aws_lambda_function.main.arn
}
resource "aws_lambda_permission" "example" {
statement_id = "AllowExecutionFromCognitoSync"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.main.function_name
principal = "cognito-sync.amazonaws.com"
source_arn = aws_cognito_identity_pool.main.arn
}
TLDR:
想知道如何处理这个问题,我们只需要在 Lambda 配置中添加一个触发器:
由于 API 网关触发器是以相同的方式添加的,因此我们应该使用 Terraform 以相同的方式进行配置:
https://aws.amazon.com/blogs/mobile/introducing-amazon-cognito-events-sync-triggers/
希望这能帮助你
英文:
You can use aws_lambda_event_source_mapping
to achieve this:
resource "aws_lambda_event_source_mapping" "example" {
event_source_arn = aws_cognito_identity_pool.main.arn
function_name = aws_lambda_function.main.arn
}
resource "aws_lambda_permission" "examle" {
statement_id = "AllowExecutionFromCognitoSync"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.main.function_name
principal = "cognito-sync.amazonaws.com"
source_arn = aws_cognito_identity_pool.main.arn
}
TLDR:
Looking to how we can handle this, we just need to add a trigger to the lambda configuration:
As api gateway trigger is added in the same way, we should do it in the same way with terraform:
https://aws.amazon.com/blogs/mobile/introducing-amazon-cognito-events-sync-triggers/
I hope this will help you
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论