I have set up the AWS SDK for iOS to authenticate using Amazon Cognito. Here is the code that does that:
let credentials = AWSCognitoCredentialsProvider(regionType: .USEast1,
identityPoolId: IdentityManager.identityPoolId,
identityProviderManager: self)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = AWSServiceConfiguration(region: .USEast1,
credentialsProvider: credentials)
I can use this credentials provider to successfully get an identity id. From here I attempt to set up an API Gateway generated client to make a call to my lambda function.
let client = APIGatewayClient.defaultClient()
client.endpointGet() { task in
}
I've confirmed that the APIGatewayClient
has the AWSCognitoCredentialsProvider
attached to it's configuration
property and stepped through the request signing code to make sure it's requests get signed properly.
Here is the Lambda function being called by the client:
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"))
}
}
The problem is that context.identity
is null even though the request is being signed with the AWSCognitoCredentialsProvider
. What additional steps do I need to take to ensure Lambda recognizes my request is signed with a Cognito identity and populates the related field in the context
object?