Skip to content

Conversation

@sebsto
Copy link
Collaborator

@sebsto sebsto commented Dec 18, 2023

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.

  1. support the lambda object under authorizer in APIGatewayV2.swift. This allows Lambda function behind a Lambda Authorizer to gather the identity and authorization data shared by the Lambda authorizer function. The lambda object comes as an alternative to the existing jwt and iam objects.

The other additions allow Swift developers to write Lambda authorizer functions in the Swift programming language.

  1. create a new struct APIGatewayLambdaAuthorizerRequest to represent the payload sent to a Lambda authorizer function
  2. create a new struct APIGatewayLambdaAuthorizerSimpleResponse to represent the simple response from a Lambda authorizer function
  3. create a new struct APIGatewayLambdaAuthorizerPolicyResponse 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)

@sebsto
Copy link
Collaborator Author

sebsto commented Dec 18, 2023

@tomerd wdyt ?

@tomerd tomerd merged commit 997094f into awslabs:main Dec 18, 2023
@tomerd
Copy link
Contributor

tomerd commented Dec 18, 2023

thank you!

@sebsto
Copy link
Collaborator Author

sebsto commented Dec 18, 2023

Thank you @tomerd
Can you create a 0.2.0 tag for easy inclusion in Package.swift files ?

@tomerd
Copy link
Contributor

tomerd commented Dec 18, 2023

https://github.com/swift-server/swift-aws-lambda-events/releases/tag/0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants