Add support for AWS Lambda Authorizers #42
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for Lambda Authorizers as requested by issue #39
Motivation:
Lambda authorizers are Lambda functions called by Amazon API Gateway to delegate authorization decisions. There are used both by the Rest API and the HTTP API gateway (aka APIGateway and APIGatewayv2)
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html
Modifications:
This changes introduce three modifications.
The first modification allows Swift developer to write Lambda functions protected by a Lambda authorizer function.
lambda
object underauthorizer
inAPIGatewayV2.swift
. This allows Lambda function behind a Lambda Authorizer to gather the identity and authorization data shared by the Lambda authorizer function. Thelambda
object comes as an alternative to the existingjwt
andiam
objects.The other additions allow Swift developers to write Lambda authorizer functions in the Swift programming language.
APIGatewayLambdaAuthorizerRequest
to represent the payload sent to a Lambda authorizer functionAPIGatewayLambdaAuthorizerSimpleResponse
to represent the simple response from a Lambda authorizer functionAPIGatewayLambdaAuthorizerPolicyResponse
to represent the IAM policy document response from a Lambda authorizer function.The documentation has the details about Lambda authorizer response types.
This change supports the payload format v2.0 only. I didn't implement payload v1.0 because it is considered as legacy and not recommended to use for new projects.
Results:
Developers can write Lambda functions that are protected by a Lambda authorizer function (written in any language)
Developers can write Lambda authorizer function in Swift.
This change has been tested end-to-end on a sample project I wrote and validated by another developer on his own project (@GeorgePreece)