Skip to content
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

Add custom authoriser #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .project-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
6 changes: 6 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ provider:
runtime: python3.8

functions:
auth:
handler: src/functions/auth.handler

get:
handler: src/functions/hello_world.handler
events:
- http:
path: hello-world
method: get
cors: true
authorizer:
name: auth
type: request

post:
handler: src/functions/add.handler
Expand Down
37 changes: 37 additions & 0 deletions src/functions/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Provide handler for the auth method.
"""
from typing import Any, Dict

from aws_lambda_powertools.utilities.typing import LambdaContext


def handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any]:
"""
Lambda function handler.

Arguments:
event (dict): the event with data to process.
context (LambdaContext): the information about the invocation, function, and runtime environment.

Returns:
The response as dict.
"""
# auth_token = ...
resource = event.get('methodArn')
principal_id = None
effect = 'Allow'
response = {
'principalId': principal_id,
'policyDocument': {
'Version': '2022-02-14',
'Statement': [
{
'Action': 'execute-api:Invoke',
'Effect': effect,
'Resource': resource,
},
],
},
}
return response
Empty file added src/utils/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions src/utils/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Provide utils for authentication.
"""