When I create a resource/method in AWS API Gateway API I can create one of the following methods: DELETE
, GET
, HEAD
, OPTIONS
, PATCH
or POST
.
If I choose GET
then API Gateway doesn't pass authentication details; but for POST
it does.
For GET
should I be adding the cognito credentials to the URL of my GET
? or just never use GET
and use POST
for all authenticated calls?
My set-up in API Gateway/Lambda:
I created a Resource and two methods: GET
and POST
Under Authorization Settings I set Authorization to AWS_AIM
For this example there is no Request Model
Under Method Execution I set Integration type to Lambda Function and I check Invoke with caller credentials
(I also set Lambda Region and Lambda Function)
I leave Credentials cache
unchecked.
For Body Mapping Templates, I set Content-Type
to `application/json' and the Mapping Template to
{ "identity" : "$input.params('identity')"}
In my Python Lambda function:
def lambda_handler(event, context):
print context.identity
print context.identity.cognito_identity_id
return True
Running the Python function:
For the GET
context.identity is None
For the POST
context.identity has a value and context.identity.cognito_identity_id
has the correct value.