具有Cognito用户池授权者和Lambda的API网关 [英] API Gateway with Cognito User Pool Authorizer and Lambda

查看:110
本文介绍了具有Cognito用户池授权者和Lambda的API网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个体系结构,正在将API网关与Cognito用户池授权器一起使用,并从客户端ReST调用在授权标头中传递IdToken。

I am having an Architecture where I am using API Gateway with Cognito User Pool Authorizer and I am passing the IdToken in Authorization Header from client side ReST call.

它工作正常。

我需要Lambda中的cognitoIdentityId。

尝试身体API网关中集成请求中的模板映射

Tried Body Template Mapping in Integration Request in API Gateway

内容类型-application / json

Content type - application/json

{
"cognito-identity" : "$context.identity.cognitoIdentityId"
}

它不发送身份ID(在事件或上下文中),并且也仅将我的有效载荷转换为该json。

It doesn't send the identityid (in event or in context) and also it transforms my payload only to this json.

如何获取在这种情况下,Lambda中的identityid和我的有效载荷完好无损?

How to get the identityid in Lambda in this scenario with my payload intact?

推荐答案

仅当您使用Cognito身份凭证时,Cognito身份ID才可用。如果您想获取有关通过Athorizer授权的Cognito用户池用户的信息,则可在 context.authorizer.claims 地图中找到。

The Cognito Identity Id will only be available if you use Cognito Identity Credentials. If you want to get information about the Cognito User Pool user authorized via an athorizer, it will be available in the context.authorizer.claims map.

请参见本文档更多信息。

此外,如果您希望此值在Lambda函数中可用,它将在event.requestContext.authorizer.claims地图中(如果您使用

Also, if you want this value to be available in your Lambda function, it will be in the event.requestContext.authorizer.claims map (if you are using Lambda proxy integration), or wherever you've chosen to map it with your mapping template (if you are not using proxy integration).

编辑以修复该问题,或者使用Lambda代理集成),或者选择使用映射模板对其进行映射的任何位置(如果未使用代理集成)。错字。

这篇关于具有Cognito用户池授权者和Lambda的API网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆