Skip to content

Add support for AWS Lambda Authorizers #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 18, 2023

Conversation

sebsto
Copy link
Contributor

@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
Contributor Author

sebsto commented Dec 18, 2023

@tomerd wdyt ?

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

tomerd commented Dec 18, 2023

thank you!

@sebsto
Copy link
Contributor 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