

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# S3
<a name="sam-property-function-s3"></a>

描述 `S3` 事件源类型的对象。

## 语法
<a name="sam-property-function-s3-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-s3-syntax.yaml"></a>

```
  [Bucket](#sam-function-s3-bucket): String
  [Events](#sam-function-s3-events): String | List
  [Filter](#sam-function-s3-filter): [NotificationFilter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfiguration-config-filter.html)
```

## Properties
<a name="sam-property-function-s3-properties"></a>

 `Bucket`   <a name="sam-function-s3-bucket"></a>
S3 桶名称。此存储桶必须存在于同一模板中。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性类似于`AWS::S3::Bucket`资源的`[BucketName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-name)`属性。在 SAM 中此为必填字段。此字段仅接受对此模板中创建的 S3 存储桶的引用

 `Events`   <a name="sam-function-s3-events"></a>
调用 Lambda 函数的 Amazon S3 桶事件。有关有效值的列表，请参阅 [Amazon S3 支持的事件类型](https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#supported-notification-event-types)。  
*类型*：字符串 \$1 列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::S3::Bucket``LambdaConfiguration`数据类型的`[Event](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig-lambdaconfig.html#cfn-s3-bucket-notificationconfig-lambdaconfig-event)`属性。

 `Filter`   <a name="sam-function-s3-filter"></a>
确定哪些 Amazon S3 对象调用 Lambda 函数的筛选规则。有关 Amazon S3 键名筛选的信息，请参阅*《Amazon Simple Storage Service 用户指南》*中的[配置 Amazon S3 事件通知](https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html)。  
*类型*：[NotificationFilter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfiguration-config-filter.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::S3::Bucket``LambdaConfiguration`数据类型的`[Filter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfiguration-config-filter.html)`属性。

## 示例
<a name="sam-property-function-s3--examples"></a>

### S3 事件
<a name="sam-property-function-s3--examples--s3-event"></a>

S3 事件示例。

#### YAML
<a name="sam-property-function-s3--examples--s3-event--yaml"></a>

```
Events:
  S3Event:
    Type: S3
    Properties:
      Bucket:
        Ref: ImagesBucket     # This must be the name of an S3 bucket declared in the same template file
      Events: s3:ObjectCreated:*
      Filter:
        S3Key:
          Rules:
          - Name: prefix      # or "suffix"
            Value: value      # The value to search for in the S3 object key names
```