Zappa icon indicating copy to clipboard operation
Zappa copied to clipboard

zappa schedule doesnt work when event function string too long

Open opqpop opened this issue 4 years ago • 1 comments
trafficstars

Context

Running below zappa_settings.json won't work for Cloudwatch event -> lambda, because the function name is too long and lambda tries to call "aws.lambda_service.pipeline.core.lambda_update_price_col.ma" instead of "aws.lambda_service.pipeline.core.lambda_update_price_col.main", since zappa handler looks at the resource name of the cloud watch event, which has a max char limit

    "update_price_col_prod": {
        "aws_region": "us-east-1",
        "profile_name": "default",
        "project_name": "test",
        "events": [{
            "function": "aws.lambda_service.pipeline.core.lambda_update_price_col.main",
            "expression": "cron(0/1 3 * * ? *)"
        }],
        "lambda_description": "update_price_col",
    }

Offending code is here: https://github.com/zappa/Zappa/blob/89e99174ded0abdcbc5740c57c25baf93e55d468/zappa/handler.py#L385

Expected Behavior

Should work regardless of how long the name. We can't refactor our codebase as there's too many files, so we have to rename our files to be shorter if we want to use zappa schedule. For now, most of the devs just stopped using zappa and manually create the lambda / cloudwatch event which is not ideal.

Actual Behavior



2021-09-13T20:49:01.687-07:00Copy[DEBUG]	2021-09-14T03:49:01.687Z	5a5590fa-4a6c-4a5f-82b0-a15d26273904	Zappa Event: {'time': '2021-09-14T03:49:00Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '915544849818', 'region': 'us-east-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:us-east-1:915544849818:rule/-aws.lambda_service.pipeline.core.lambda_run_update_price_col.ma'], 'id': '84c0f87c-dba8-1895-e277-f1a1454cc35c', 'kwargs': {}} | [DEBUG] 2021-09-14T03:49:01.687Z 5a5590fa-4a6c-4a5f-82b0-a15d26273904 Zappa Event: {'time': '2021-09-14T03:49:00Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '915544849818', 'region': 'us-east-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:us-east-1:915544849818:rule/-aws.lambda_service.pipeline.core.lambda_run_update_price_col.ma'], 'id': '84c0f87c-dba8-1895-e277-f1a1454cc35c', 'kwargs': {}}
-- | --


2021-09-13T20:49:11.542-07:00Copy[ERROR] AttributeError: module 'aws.lambda_service.pipeline.core.lambda_run_update_price_col' has no attribute 'ma'Traceback (most recent call last):  File "/code/zappa/handler.py", line 657, in lambda_handler    return LambdaHandler.lambda_handler(event, context)  File "/code/zappa/handler.py", line 254, in lambda_handler    return handler.handler(event, context)  File "/code/zappa/handler.py", line 389, in handler    app_function = self.import_module_and_get_function(whole_function)  File "/code/zappa/handler.py", line 246, in import_module_and_get_function    app_function = getattr(app_module, function) | [ERROR] AttributeError: module 'aws.lambda_service.pipeline.core.lambda_run_update_price_col' has no attribute 'ma' Traceback (most recent call last):   File "/code/zappa/handler.py", line 657, in lambda_handler     return LambdaHandler.lambda_handler(event, context)   File "/code/zappa/handler.py", line 254, in lambda_handler     return handler.handler(event, context)   File "/code/zappa/handler.py", line 389, in handler     app_function = self.import_module_and_get_function(whole_function)   File "/code/zappa/handler.py", line 246, in import_module_and_get_function     app_function = getattr(app_module, function)
-- | --

Possible Fix

Fix is probably to pass the entire function string, instead of relying on the "resources" field from cloudwatch event / eventbridge:

# Input transformer
{"account":"$.account","detail":"$.detail","detail-type":"$.detail-type","id":"$.id","region":"$.region","resources":"$.resources","source":"$.source","time":"$.time","version":"$.version"}

image

opqpop avatar Sep 14 '21 04:09 opqpop

I've hit this issue in the past... I would be nice if zappa could throw an error if the generated name is to long.

monkut avatar Jul 16 '22 02:07 monkut

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

github-actions[bot] avatar Apr 03 '24 18:04 github-actions[bot]

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.

github-actions[bot] avatar Apr 13 '24 20:04 github-actions[bot]