无服务器框架 |如何在前缀路径中使用通配符 (*)
Serverless Framework | How to use wildcard (*) in prefix path
我正在使用无服务器框架创建 S3 Lambda 触发器:
functions:
profilePictureInput:
handler: triggers/handler.profilePictureInput
memorySize: 10240
timeout: 25
events:
- s3:
bucket: ${self:custom.mediaInputBucketName}
existing: true
event: s3:ObjectCreated:*
rules:
- prefix: private/*/profile-pictures
问题:是否可以在前缀路径中使用通配符?
我希望在对象键为 private/foo/profile-pictures
或 private/bar/profile-pictures
时触发 lambda。
上面的例子似乎不起作用(lambda 未触发)
不,你不能。
Because the wildcard asterisk character (*) is a valid character that
can be used in object key names, Amazon S3 literally interprets the
asterisk as a prefix or suffix filter. You can't use the wildcard
character to represent multiple characters for the prefix or suffix
object key name filter.
您必须将所有前缀值字符串注册到 S3 事件。对于您的情况,它将如下所示:
functions:
profilePictureInput:
handler: triggers/handler.profilePictureInput
memorySize: 10240
timeout: 25
events:
- s3:
bucket: ${self:custom.mediaInputBucketName}
existing: true
event: s3:ObjectCreated:*
rules:
- prefix: private/foo/profile-pictures
- prefix: private/bar/profile-pictures
我正在使用无服务器框架创建 S3 Lambda 触发器:
functions:
profilePictureInput:
handler: triggers/handler.profilePictureInput
memorySize: 10240
timeout: 25
events:
- s3:
bucket: ${self:custom.mediaInputBucketName}
existing: true
event: s3:ObjectCreated:*
rules:
- prefix: private/*/profile-pictures
问题:是否可以在前缀路径中使用通配符?
我希望在对象键为 private/foo/profile-pictures
或 private/bar/profile-pictures
时触发 lambda。
上面的例子似乎不起作用(lambda 未触发)
不,你不能。
Because the wildcard asterisk character (*) is a valid character that can be used in object key names, Amazon S3 literally interprets the asterisk as a prefix or suffix filter. You can't use the wildcard character to represent multiple characters for the prefix or suffix object key name filter.
您必须将所有前缀值字符串注册到 S3 事件。对于您的情况,它将如下所示:
functions:
profilePictureInput:
handler: triggers/handler.profilePictureInput
memorySize: 10240
timeout: 25
events:
- s3:
bucket: ${self:custom.mediaInputBucketName}
existing: true
event: s3:ObjectCreated:*
rules:
- prefix: private/foo/profile-pictures
- prefix: private/bar/profile-pictures