关于使用Go编写Cognito Post-Auth Lambda的问题

0

【以下的问题经过翻译处理】 我为Cognito编写了一个非常简单的后身份认证 Lambda,代码如下:

func HandleRequest(ctx context.Context, e events.CognitoEventUserPoolsPostAuthentication ) error {
	eventJson, _ := json.MarshalIndent(e, "", "  ")
	eventString := strings.ReplaceAll(string(eventJson), "\n", "\r")

	log.Printf("EVENT: %s", eventString)
	return nil
}

func main() {
	lambda.Start(HandleRequest)
}

目前它只是用于记录活动。但是,当我将其作为后身份认证触发器连接到用户池时,OAuth2就无法工作。错误消息是“联系管理员”。

我想我需要做一些实际的操作,而不仅仅是返回 error = nil。然而,我在go语言中找不到任何示例。

Javascript 示例的结束方式是:

// Return to Amazon Cognito
callback(null, event);

在 'go' 中的期望也是这样 - 我返回 (events.CognitoEventUserPoolsPostAuthentication, error) 并将原始事件发送回去吗?

profile picture
专家
已提问 5 个月前38 查看次数
1 回答
0

【以下的回答经过翻译处理】 我明白了。我想要更多地控制事物,所以我正在使用它:

''' func HandleRequest(ctx context.Context, request events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) { ... } '''

效果很好。之前它会负责编组/解组,这很好,现在我必须自己做,但这还不错。我确实希望响应“ Body”只是 interface{} 并且它会根据 Content-Type 自动编组/解组,但这很好。

我在 Kotlin 和 Spring 中这样做时确实怀念的一件事是能够抛出异常,并编写一个 ExceptionMapper 来设置适当的 http 状态代码。

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则