Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 5 additions & 1 deletion configs/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
"name": "aws",
"aws": {
"region": "us-east-1",
"lambda-role": ""
"lambda-role": "",
"resources": {
"use-function-url": false,
"function-url-auth-type": "NONE"
}
},
"azure": {
"region": "westeurope"
Expand Down
60 changes: 41 additions & 19 deletions sebs/aws/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,13 @@ def delete_function(self, func_name: str) -> None:
except Exception:
self.logging.error("Function {} does not exist!".format(func_name))

def delete_function_url(self, func_name: str) -> bool:
Comment thread
Sharayu1418 marked this conversation as resolved.
Outdated
"""
Delete the Function URL associated with a Lambda function.
Returns True if deleted successfully, False if it didn't exist.
"""
return self.config.resources.delete_function_url(func_name, self.session)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

@staticmethod
def parse_aws_report(
log: str, requests: Union[ExecutionResult, Dict[str, ExecutionResult]]
Expand Down Expand Up @@ -692,7 +699,7 @@ def parse_aws_report(
def cleanup_resources(self, dry_run: bool = False) -> dict:
"""Delete allocated resources on AWS.
Currently it deletes the following resources:
* Lambda functions and its HTTP API triggers.
* Lambda functions and its HTTP API/Function URL triggers.
* CloudWatch log groups of the functions.
* DynamoDB tables created for the benchmark.
* S3 buckets and their content created for the benchmark.
Expand Down Expand Up @@ -720,6 +727,10 @@ def cleanup_resources(self, dry_run: bool = False) -> dict:
self.session, self.cache_client, dry_run
)

result["Function URLs"] = self.config.resources.cleanup_function_urls(
self.session, self.cache_client, dry_run
)

result["CloudWatch log groups"] = self.config.resources.cleanup_cloudwatch_logs(
list(functions.keys()), self.session, dry_run
)
Expand Down Expand Up @@ -874,28 +885,39 @@ def create_trigger(self, func: Function, trigger_type: Trigger.TriggerType) -> T
Raises:
RuntimeError: If trigger type is not supported
"""
from sebs.aws.triggers import HTTPTrigger
from sebs.aws.triggers import HTTPTrigger, FunctionURLTrigger

function = cast(LambdaFunction, func)

trigger: Trigger
if trigger_type == Trigger.TriggerType.HTTP:
api_name = "{}-http-api".format(function.name)
http_api = self.config.resources.http_api(api_name, function, self.session)
# https://aws.amazon.com/blogs/compute/announcing-http-apis-for-amazon-api-gateway/
# but this is wrong - source arn must be {api-arn}/*/*
self.get_lambda_client().add_permission(
FunctionName=function.name,
StatementId=str(uuid.uuid1()),
Action="lambda:InvokeFunction",
Principal="apigateway.amazonaws.com",
SourceArn=f"{http_api.arn}/*/*",
)
trigger = HTTPTrigger(http_api.endpoint, api_name)
self.logging.info(
f"Created HTTP trigger for {func.name} function. "
"Sleep 5 seconds to avoid cloud errors."
)
time.sleep(5)
if self.config.resources.use_function_url:
# Use Lambda Function URL (no 29-second timeout limit)
func_url = self.config.resources.function_url(function, self.session)
trigger = FunctionURLTrigger(
func_url.url, func_url.function_name, func_url.auth_type
)
self.logging.info(f"Created Function URL trigger for {func.name} function.")
else:
# Use API Gateway (default, for backward compatibility)
api_name = "{}-http-api".format(function.name)
http_api = self.config.resources.http_api(api_name, function, self.session)
# https://aws.amazon.com/blogs/compute/announcing-http-apis-for-amazon-api-gateway/
# but this is wrong - source arn must be {api-arn}/*/*
self.get_lambda_client().add_permission(
FunctionName=function.name,
StatementId=str(uuid.uuid1()),
Action="lambda:InvokeFunction",
Principal="apigateway.amazonaws.com",
SourceArn=f"{http_api.arn}/*/*",
)
trigger = HTTPTrigger(http_api.endpoint, api_name)
self.logging.info(
f"Created HTTP API Gateway trigger for {func.name} function. "
"Sleep 5 seconds to avoid cloud errors."
)
time.sleep(5)

trigger.logging_handlers = self.logging_handlers
elif trigger_type == Trigger.TriggerType.LIBRARY:
# should already exist
Expand Down
Loading