

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

# MQ
<a name="sam-property-function-mq"></a>

描述 `MQ` 事件源类型的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中[结合 Amazon MQ 使用 Lambda](https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html)。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)资源。

**注意**  
要在虚拟私有云（VPC）中建立 Amazon MQ 队列并连接到公共网络中的 Lambda 函数，函数的执行角色必须包含以下权限：  
`ec2:CreateNetworkInterface`
`ec2:DeleteNetworkInterface`
`ec2:DescribeNetworkInterfaces`
`ec2:DescribeSecurityGroups`
`ec2:DescribeSubnets`
`ec2:DescribeVpcs`
有关更多信息，请参阅《*AWS Lambda 开发人员指南*》中的[执行角色权限](https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html#events-mq-permissions)。

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

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

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

```
  [BatchSize](#sam-function-mq-batchsize): Integer
  [Broker](#sam-function-mq-broker): String
  DynamicPolicyName: Boolean
  [Enabled](#sam-function-mq-enabled): Boolean
  [FilterCriteria](#sam-function-mq-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  KmsKeyArn: String 
  [MaximumBatchingWindowInSeconds](#sam-function-mq-maximumbatchingwindowinseconds): Integer
  [Queues](#sam-function-mq-queues): List
  [SecretsManagerKmsKeyId](#sam-function-mq-secretsmanagerkmskeyid): String
  [SourceAccessConfigurations](#sam-function-mq-sourceaccessconfigurations): List
```

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

 `BatchSize`   <a name="sam-function-mq-batchsize"></a>
要在单个批次中检索的最大项目数。  
*类型*：整数  
*必需*：否  
*默认值*：100  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。  
*最小值*：`1`  
*最大值*：`10000`

 `Broker`   <a name="sam-function-mq-broker"></a>
Amazon MQ 代理的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `DynamicPolicyName`   <a name="sam-function-mq-dynamicpolicyname"></a>
默认情况下， AWS Identity and Access Management (IAM) 策略名称是`SamAutoGeneratedAMQPolicy`为了向后兼容。指定 `true` 对 IAM policy 使用自动生成的名称。此名称包含 Amazon MQ 事件源逻辑 ID。  
使用多个 Amazon MQ 事件源时，请指定 `true`，以避免重复的 IAM policy 名称。
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Enabled`   <a name="sam-function-mq-enabled"></a>
如果为 `true`，则事件源映射处于活动状态。要暂停轮询和调用，设置为 `false`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-mq-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `KmsKeyArn`   <a name="sam-function-mq-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-mq-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `Queues`   <a name="sam-function-mq-queues"></a>
要使用的 Amazon MQ 代理目的地队列的名称。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Queues](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-queues)`属性。

 `SecretsManagerKmsKeyId`   <a name="sam-function-mq-secretsmanagerkmskeyid"></a>
来自的客户托管密钥的 AWS Key Management Service (AWS KMS) 密钥 ID AWS Secrets Manager。将来自 Secrets Manager 的客户托管密钥与不包含 `kms:Decrypt` 权限的 Lambda 执行角色一起使用时，此属性是必需的。  
此属性的值为 UUID。例如：`1abc23d4-567f-8ab9-cde0-1fab234c5d67`。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceAccessConfigurations`   <a name="sam-function-mq-sourceaccessconfigurations"></a>
身份验证协议或虚拟主机的数组。使用[SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration.html)数据类型进行指定。  
对于 `MQ` 事件源类型，唯一有效的配置类型是 `BASIC_AUTH` 和 `VIRTUAL_HOST`。  
+ **`BASIC_AUTH`** – 存储您的代理凭证的 Secrets Manager 密钥。要使用此类型，凭证必须采用以下格式：`{"username": "your-username", "password": "your-password"}`。只允许使用一个类型为 `BASIC_AUTH` 的对象。
+ **`VIRTUAL_HOST`** - 您的 RabbitMQ 代理中虚拟主机的名称。Lambda 将使用此 RabbitMQ 的主机作为事件源。只允许使用一个类型为 `VIRTUAL_HOST` 的对象。
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-sourceaccessconfigurations)`属性。

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

### Amazon MQ 事件源
<a name="sam-property-function-mq--examples--amazon-mq-event-source"></a>

以下是 Amazon MQ 代理的 `MQ` 事件源类型示例。

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

```
Events:
  MQEvent:
    Type: MQ
    Properties:
      Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
      Queues: List of queues
      SourceAccessConfigurations:
        - Type: BASIC_AUTH
          URI: arn:aws:secretsmanager:us-east-1:01234567890:secret:MyBrokerSecretName
      BatchSize: 200
      Enabled: true
```