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

WIldcard in `on_s3_event objectcreated` deploys a non-working trigger #1209

Closed
dgallitelli opened this issue Aug 9, 2019 · 3 comments
Closed
Labels

Comments

@dgallitelli
Copy link

@dgallitelli dgallitelli commented Aug 9, 2019

Creating a trigger with

@app.on_s3_event(bucket=S3_BUCKET, events=['s3:ObjectCreated:*'], prefix='uploads/*', suffix='.txt')

generates a trigger in a Lambda which does not work. in particular, the problem should be related to the Notification, since from time to time chalice deploy would generate a PutBucketNotificationConfiguration operation: Unable to validate the following destination configurations - when it creates it succesfully, it generates a strange NotificationName, for example:

Notification name: NWRhNTM3MDItNWI5YS00OTEyLWJkNDgtZGI2ZWNiNDk4ZDlj

while it should be

Notification name: b67905c9-6073-4fca-9c22-30c45100f558.

It can either be a Chalice problem or a Lambda problem. Haven't tested s3_event source before, so i can't know for sure.

@jamesls
Copy link
Member

@jamesls jamesls commented Aug 9, 2019

Can you say what specifically isn't working? One thing I noticed is that the prefix has uploads/* which means that key name would have to start with the literal characters uploads/* (prefix/suffix aren't globs). You'd probably want uploads/ instead.

With that change, everything is working when I try it out:

from chalice import Chalice

app = Chalice(app_name='s3-events-test')
app.debug = True


@app.on_s3_event(bucket='dfasdjfhasjhasdf', events=['s3:ObjectCreated:*'],
                 prefix='uploads/', suffix='.txt')
def index(event):
    app.log.debug('Handler called.')
    app.log.debug(event.key)
chalice deploy
...
aws s3 cp requirements.txt s3://dfasdjfhasjhasdf/uploads/test3.txt
upload: ./requirements.txt to s3://dfasdjfhasjhasdf/uploads/test3.txt

Then verify the handler was called:

$ chalice logs -n index
2019-08-09 15:06:13.755000 caec42 s3-events-test - DEBUG - Handler called.
2019-08-09 15:06:13.755000 caec42 s3-events-test - DEBUG - uploads/test3.txt

It might be nice to add some warnings if the prefix/suffix has *, but * is a valid char to use with a prefix/suffix, it just means the literal char *. Perhaps we can have a lint command.

@dgallitelli
Copy link
Author

@dgallitelli dgallitelli commented Aug 10, 2019

Thank you James, you were right, using the * wildcard does not work with Chalice while it is supported by the AWS Management Console. Dropping it solves the issue, you can close this now.

The idea of the lint command or to support wildcards might be an interesting feature, I'll let you decide on that 😄

Thanks!

@dgallitelli dgallitelli changed the title on_s3_event objectcreated generates a non-working trigger WIldcard in `on_s3_event objectcreated` generates a non-working trigger Aug 10, 2019
@dgallitelli dgallitelli changed the title WIldcard in `on_s3_event objectcreated` generates a non-working trigger WIldcard in `on_s3_event objectcreated` non-working trigger Aug 10, 2019
@dgallitelli dgallitelli changed the title WIldcard in `on_s3_event objectcreated` non-working trigger WIldcard in `on_s3_event objectcreated` deploys a non-working trigger Aug 10, 2019
@jamesls
Copy link
Member

@jamesls jamesls commented Apr 22, 2020

Closing out old issue, a note was added in the docs about wildcards in #1210.

@jamesls jamesls closed this Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.