【发布时间】:2016-10-17 03:28:33
【问题描述】:
我已设置适用于 iOS 的 AWS 开发工具包以使用 Amazon Cognito 进行身份验证。这是执行此操作的代码:
let credentials = AWSCognitoCredentialsProvider(regionType: .USEast1,
identityPoolId: IdentityManager.identityPoolId,
identityProviderManager: self)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = AWSServiceConfiguration(region: .USEast1,
credentialsProvider: credentials)
我可以使用此凭据提供程序成功获取身份 ID。从这里我尝试设置一个 API Gateway 生成的客户端来调用我的 lambda 函数。
let client = APIGatewayClient.defaultClient()
client.endpointGet() { task in
}
我已确认APIGatewayClient 的configuration 属性附加了AWSCognitoCredentialsProvider,并逐步检查了请求签名代码以确保其请求得到正确签名。
这是客户端调用的 Lambda 函数:
exports.handler = function(event, context) {
console.log('context: ' + require('util').inspect(context));
if (context.identity) {
context.succeed("found cognito identity")
} else {
return context.fail(new Error("cognito identity not found"))
}
}
问题是context.identity 为空,即使请求是使用AWSCognitoCredentialsProvider 签名的。我需要采取哪些额外步骤来确保 Lambda 识别出我的请求是使用 Cognito 身份签名的并填充 context 对象中的相关字段?
【问题讨论】:
标签: ios aws-lambda amazon-cognito aws-api-gateway