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

app.lambda_context with @app.schedule #1133

Closed
danil-smirnov opened this issue May 28, 2019 · 1 comment · Fixed by #1141
Closed

app.lambda_context with @app.schedule #1133

danil-smirnov opened this issue May 28, 2019 · 1 comment · Fixed by #1141

Comments

@danil-smirnov
Copy link

Hi,

I've just examined this issue - still have questions, but the issue is closed now, so I've decided to create a new one.

The following stated in the issue:

However, the app object does expose a lambda_context property that you could access from with in the schedule event function.

I believe it't not true as I wasn't able to call app.lambda_context from a method decorated by @app.schedule.

I've tried the following code:

from chalice import Chalice

app = Chalice(app_name='chalice-lambda_context-poc')

@app.route('/')
def index():
    print('app.lambda_context.invoked_function_arn : ' + app.lambda_context.invoked_function_arn)

@app.schedule('rate(1 minute)')
def scheduled(event):
    print('event.context.invoked_function_arn: ' + event.context.invoked_function_arn)
    print('app.lambda_context.invoked_function_arn: ' + app.lambda_context.invoked_function_arn)

If you run it and check /aws/lambda/chalice-lambda_context-poc-dev-scheduled log group, there is an error raised in the second print statement:

'NoneType' object has no attribute 'invoked_function_arn': AttributeError
Traceback (most recent call last):
File "/var/task/chalice/app.py", line 1130, in __call__
return self.func(event_obj)
File "/var/task/app.py", line 13, in scheduled
print('app.lambda_context.invoked_function_arn: ' + app.lambda_context.invoked_function_arn)
AttributeError: 'NoneType' object has no attribute 'invoked_function_arn'

So it seems we can't access app.lambda_context from methods decorated by @app.schedule.

I think it's quite confusing as not obvious from the documentation which states app.lambda_context is available always.

If this is by design, I assume it should be mentioned in the docs on page
https://chalice.readthedocs.io/en/latest/api.html

@stealthycoin
Copy link
Contributor

Yes this is intentional, I updated the documentation to reflect this, the code that Kyle wrote in the comment you linked was a suggestion, not how it worked, or works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants