Aman Saran
09/17/2021, 5:21 PMidToken
from the session and use that in the Authorization
header in subsequent requests. My lambda functions are built using the serverless framework and are based heavily off the ones described in the notes-api
here: https://github.com/AnomalyInnovations/serverless-stack-demo-ext-api/tree/master/services/notes-api
From this point, the requestContext
pulled off of the event
object in the lambda seems to have the claims object correctly populated, however, the fields in the identity object all appear to be null
including cognitoIdentityId
(I'm assuming this is the equivalent of a user ID?) which I want to use as the partition key in DynamoDB.
My questions are:
1.) Is this the correct way to achieve the intended result?
2.) API Gateway seems to give me the option to use AWS IAM or the Cognito User Pool itself as an Authorizer in the method request. The example serverless.yml files seem to use AWS IAM. Is that the correct Authorizer to use here or should I use the Cognito User Pool?
3.) The documentation for AWS IAM seems to suggest signing requests using something called Signature V4. Is this different than using a token in the headers as I am attempting to do?
4.) When using AWS IAM, I get a 403 back from API gateway with an error message similar to the following: Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter.
This message does not happen when using the Cognito User Pool as my authorizer. Is this expected behavior? From doing a Google search, it appears that my request needs to be signed using the aforementioned Signature V4 system to get around this.
5.) From searching, many posts seem to suggest that I need to enable the Invoke with caller credentials
setting in the integration request portion of the API Gateway set up. This option is greyed out when using the Cognito User Pool option and is only available if I use AWS IAM. Is this something I need to get the identity information?
6.) Not really a question but I did also try using a mapping template to map the cognito identity ID from the context to a custom field, which was suggested by some posts I read, and that also returned null.
Sorry for the lengthy post! I've been blocked by my lack of understanding of Cognito and API Gateway for the last few days and I'm trying to figure out how to properly set these things up so I can move forward. Thanks for any help!Frank
Frank
Frank
Aman Saran
09/20/2021, 7:01 PMFrank
Frank
Aman Saran
09/21/2021, 3:35 AM