in chalice/package.py [0:0]
def _generate_s3bucketnotification(self, resource, template):
# type: (models.S3BucketNotification, Dict[str, Any]) -> None
bnotify = {
'events': resource.events,
'lambda_function_arn': self._fref(resource.lambda_function)
}
if resource.prefix:
bnotify['filter_prefix'] = resource.prefix
if resource.suffix:
bnotify['filter_suffix'] = resource.suffix
# we use the bucket name here because we need to aggregate
# all the notifications subscribers for a bucket.
# Due to cyclic references to buckets created in terraform
# we also try to detect and resolve.
if '{aws_s3_bucket.' in resource.bucket:
bucket_name = resource.bucket.split('.')[1]
else:
bucket_name = resource.bucket
template['resource'].setdefault(
'aws_s3_bucket_notification', {}).setdefault(
bucket_name + '_notify',
{'bucket': resource.bucket}).setdefault(
'lambda_function', []).append(bnotify)
template['resource'].setdefault('aws_lambda_permission', {})[
resource.resource_name] = {
'statement_id': resource.resource_name,
'action': 'lambda:InvokeFunction',
'function_name': self._fref(resource.lambda_function),
'principal': self._options.service_principal('s3'),
'source_account': '${data.aws_caller_identity.chalice.account_id}',
'source_arn': ('arn:${data.aws_partition.chalice.partition}:'
's3:::%s' % resource.bucket)
}