

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AW-事件規則-拉姆達
<a name="aws-events-rule-lambda"></a>

![](http://docs.aws.amazon.com/zh_tw/solutions/latest/constructs/images/experimental.png)


 所有類都在積極開發中，並且在任何未來版本中都會受到非向後兼容的更改或刪除。這些不受[語義版本控制](https://semver.org/)模型。這意味著，雖然您可以使用它們，但在升級到此軟件包的較新版本時，您可能需要更新源代碼。

**請注意：** 為了確保功能正確，專案中的 AWS 解決方案建構套件和 AWS CDK 套件必須是相同的版本。


|  **語言**  |  **套件**  | 
| --- | --- | 
|  ![](http://docs.aws.amazon.com/zh_tw/solutions/latest/constructs/images/python.png) Python  |  aws\_solutions\_constructs.aws\_events\_rule\_lambda  | 
|  ![](http://docs.aws.amazon.com/zh_tw/solutions/latest/constructs/images/typescript.png) TypeScript  |  @aws-solutions-constructs/aws-events-rule-lambda  | 
|  ![](http://docs.aws.amazon.com/zh_tw/solutions/latest/constructs/images/java.png) Java  |  software.amazon.awsconstructs.services.eventsrulelambda  | 

## Overview
<a name="overview-9"></a>

 此 AWS 解決方案建構實作 AWS 事件規則和 AWS Lambda 函數。

 下面是 TypeScript 中的最小可部署模式定義：

```
const { EventsRuleToLambdaProps, EventsRuleToLambda } from '@aws-solutions-constructs/aws-events-rule-lambda';

const props: EventsRuleToLambdaProps = {
    lambdaFunctionProps: {
        runtime: lambda.Runtime.NODEJS_14_X,
        // This assumes a handler function in lib/lambda/index.js
        code: lambda.Code.fromAsset(`${__dirname}/lambda`),
        handler: 'index.handler'
    },
    eventRuleProps: {
      schedule: events.Schedule.rate(Duration.minutes(5))
    }
};

new EventsRuleToLambda(this, 'test-events-rule-lambda', props);
```

## Initializer
<a name="initializer-9"></a>

```
new EventsRuleToLambda(scope: Construct, id: string, props: EventsRuleToLambdaProps);
```

 *參數* 
+  scope[https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) 
+  id`string` 
+  提案[`EventsRuleToLambdaProps`](#pattern-construct-props-9) 

## 模式建立道具
<a name="pattern-construct-props-9"></a>


|  **名稱**  |  **類型**  |  **描述**  | 
| --- | --- | --- | 
|  現在還有蘭姆達伯？  |  [https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)  |  Lambda 函數對象的現有實例，提供這個和lambdaFunctionProps會造成錯誤。 | 
|  拉姆針灸道具  |  [https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)  |  選用的使用者提供的屬性來覆寫 Lambda 函數的預設屬性。忽略existingLambdaObj提供。 | 
|  事件規則道具  |  [https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html)  |  使用者提供的事件規則來覆寫預設值  | 

## 模式性質
<a name="pattern-properties-9"></a>


|  **名稱**  |  **類型**  |  **描述**  | 
| --- | --- | --- | 
|  事件規則  |  [https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html)  |  傳回模式所建立之事件規則的實體。 | 
|  LambdaFAULT  |  [https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)  |  返回由模式創建的 Lambda 函數的實例。 | 

## 預設設定
<a name="default-settings-9"></a>

 此模式的開箱即用實現沒有任何覆蓋將設置以下默認值：

### Amazon CloudWatch Events 規則
<a name="amazon-cloudwatch-events-rule"></a>
+  授與最低權限權限給 CloudWatch 事件以觸發 Lambda 函數 

### AWS Lambda 功能
<a name="aws-lambda-function-5"></a>
+  針對 Lambda 函數設定有限權限存取 IAM 角色 
+  針對 NodeJS Lambda 函數啟用具有持續作用的重複使用連線 
+  啟用 X-Ray 追蹤
+  SET DEFAULT
  +  `AWS_NODEJS_CONNECTION_REUSE_ENABLED`（對於節點 10.x 和更高版本的函數）

## Architecture
<a name="architecture-9"></a>

![](http://docs.aws.amazon.com/zh_tw/solutions/latest/constructs/images/aws-events-rule-lambda.png)


## GitHub
<a name="github-9"></a>


<table>
<thead>
  <tr><th colspan="2"> 要查看此模式的代碼，創建/查看問題和提取請求，以及更多： </th></tr>
</thead>
<tbody>
  <tr><td> ![](http://docs.aws.amazon.com/zh_tw/solutions/latest/constructs/images/GitHub-Mark-32px.png) </td><td> [@aws-解決方案-構造/aw-事件-規則-lambda](https://github.com/awslabs/aws-solutions-constructs/tree/master/source/patterns/%40aws-solutions-constructs/aws-events-rule-lambda) </td></tr>
</tbody>
</table>
