

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

# 在 Infrastructure Composer 的視覺化畫布上連接卡片
<a name="reference-navigation-gestures-connect"></a>

使用此主題來了解如何在 Infrastructure Composer 中連接卡片。本節包含有關連接增強型元件卡和標準元件卡的詳細資訊。它也提供一些範例，說明卡片連線的不同方式。

## 連接增強型元件卡
<a name="reference-navigation-gestures-connect-enhanced"></a>

在增強型元件卡上，連接埠會以視覺化方式識別可進行連線的位置。
+ 卡片右側的連接埠表示卡片有機會叫用另一張卡片。
+ 卡片左側的連接埠表示卡片有機會被另一張卡片叫用。

按一下一張卡片的右連接埠並將其拖曳至另一張卡片的左連接埠，以將卡片連接在一起。

![正在連線至 Lambda 函數的 API Gateway 卡。](http://docs.aws.amazon.com/zh_tw/infrastructure-composer/latest/dg/images/aac_use_con_02.png)


當您建立連線時，會顯示一則訊息，讓您知道連線是否成功。選取訊息以查看 Infrastructure Composer 如何變更以佈建連線。如果連線失敗，您可以選取**範本檢視**以手動更新您的基礎設施程式碼來佈建連線。
+ 成功時，請按一下訊息以檢視**變更檢查程式**。在這裡，您可以查看修改了哪些 Infrastructure Composer 來佈建您的連線。
+ 失敗時，會顯示訊息。您可以選取**範本檢視**，並手動更新您的基礎設施程式碼來佈建連線。

![從畫面底部調出 Change Inspector。](http://docs.aws.amazon.com/zh_tw/infrastructure-composer/latest/dg/images/aac_use_ci_02.gif)


當您將增強型元件卡連接在一起時， Infrastructure Composer 會自動在範本中建立基礎設施程式碼，以佈建資源之間的事件驅動關係。

## 連接標準元件卡 （標準 IaC 資源卡）
<a name="reference-navigation-gestures-connect-standard"></a>

標準 IaC 資源卡不包含用於建立與其他資源連線的連接埠。在[卡片組態](using-composer-standard-cards.md)期間，您可以在應用程式的範本中指定事件驅動關係， Infrastructure Composer 會自動偵測這些連線，並在卡片之間使用虛線將它們視覺化。以下是標準元件卡與增強型元件卡之間的連線範例：

![連接至增強型元件卡的標準元件卡。](http://docs.aws.amazon.com/zh_tw/infrastructure-composer/latest/dg/images/aac_use_con_04.png)


下列範例顯示 Lambda 函數如何與 Amazon API Gateway 靜態 API 連線：

```
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyApi:
    Type: 'AWS::ApiGateway::RestApi'
    Properties:
      Name: MyApi

  ApiGatewayMethod:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      HttpMethod: POST  # Specify the HTTP method you want to use (e.g., GET, POST, PUT, DELETE)
      ResourceId: !GetAtt MyApi.RootResourceId
      RestApiId: !Ref MyApi
      AuthorizationType: NONE
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: POST
        Uri: !Sub
          - arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunctionArn}/invocations
          - { LambdaFunctionArn: !GetAtt MyLambdaFunction.Arn }
      MethodResponses:
        - StatusCode: 200

  MyLambdaFunction:
    Type: 'AWS::Lambda::Function'
    Properties:
      Handler: index.handler
      Role: !GetAtt LambdaExecutionRole.Arn
      Runtime: nodejs14.x
      Code:
        S3Bucket: your-bucket-name
        S3Key: your-lambda-zip-file.zip

  LambdaExecutionRole:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
            Action: 'sts:AssumeRole'
      Policies:
        - PolicyName: LambdaExecutionPolicy
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource: 'arn:aws:logs:*:*:*'
              - Effect: Allow
                Action:
                  - 'lambda:InvokeFunction'
                Resource: !GetAtt MyLambdaFunction.Arn
```

在上述範例中， `ApiGatewayMethod:` 下列出的程式碼片段會`Integration:`指定連接兩張卡片的事件驅動關係。