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

zappa schedule doesnt work when event function string too long #1036

Closed
opqpop opened this issue Sep 14, 2021 · 3 comments
Closed

zappa schedule doesnt work when event function string too long #1036

opqpop opened this issue Sep 14, 2021 · 3 comments
Labels
auto-closed [Bot] Closed, details in comments next-release-candidate no-activity [Bot] Closing soon if no new activity

Comments

@opqpop
Copy link

opqpop commented Sep 14, 2021

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:

whole_function = event["resources"][0].split("/")[-1].split("-")[-1]

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

@monkut
Copy link
Collaborator

monkut commented Jul 16, 2022

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.

Copy link

github-actions bot commented Apr 3, 2024

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 github-actions bot added the no-activity [Bot] Closing soon if no new activity label Apr 3, 2024
Copy link

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 github-actions bot added the auto-closed [Bot] Closed, details in comments label Apr 13, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-closed [Bot] Closed, details in comments next-release-candidate no-activity [Bot] Closing soon if no new activity
Projects
None yet
Development

No branches or pull requests

2 participants