Skip to content

Commit aebe524

Browse files
feat: add API endpoint output and permissions for authorizer Lambda function
1 parent 1269417 commit aebe524

File tree

1 file changed

+22
-2
lines changed
  • python/amazon-verified-permissions-rest-api/stack

1 file changed

+22
-2
lines changed

python/amazon-verified-permissions-rest-api/stack/main.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from aws_cdk import (
22
Stack,
3+
aws_iam,
34
aws_lambda as _lambda,
5+
CfnOutput,
46
)
57
from constructs import Construct
68

@@ -37,6 +39,18 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
3739
"TOKEN_TYPE": "accessToken",
3840
},
3941
)
42+
policy_statement = aws_iam.PolicyStatement(
43+
actions=[
44+
"verifiedpermissions:isAuthorizedWithToken",
45+
"logs:PutLogEvents",
46+
],
47+
resources=["*"],
48+
effect=aws_iam.Effect.ALLOW,
49+
)
50+
51+
# Grant the Lambda function permissions to call Verified Permissions and write logs
52+
authorizer.role.add_to_policy(policy_statement)
53+
4054
# Create Lambda functions
4155
admin_lambda = _lambda.Function(
4256
self,
@@ -54,13 +68,19 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
5468
handler="main.handler",
5569
)
5670

57-
5871
# Create REST API
59-
API(
72+
apigw = API(
6073
self,
6174
"API",
6275
authorizer=authorizer,
6376
admin_lambda=admin_lambda,
6477
user_lambda=user_lambda,
6578
)
6679

80+
# Output the API endpoint
81+
CfnOutput(
82+
self,
83+
"ApiEndpoint",
84+
value=apigw.api.url,
85+
description="API Gateway endpoint URL",
86+
)

0 commit comments

Comments
 (0)