

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

# 在 Amazon MWAA 上管理您自己的 Amazon VPC 端點
<a name="vpc-endpoint-management"></a>

Amazon MWAA 使用 Amazon VPC 端點與設定 Apache Airflow 環境所需的各種 AWS 服務整合。有兩個主要使用案例適用於管理您的自有端點：

1. 這表示當您使用 [AWS Organizations](https://aws.amazon.com/organizations/)管理多個 AWS 帳戶 和共用資源時，可以在共用的 Amazon VPC 中建立 Apache Airflow 環境。

1. 它可讓您將許可縮小到使用端點的特定資源，以使用更嚴格的存取政策。

如果您選擇管理自己的 VPC 端點，則需負責為環境 RDS for PostgreSQL 資料庫和環境 Web 伺服器建立自己的端點。

如需 Amazon MWAA 如何在雲端中部署 Apache Airflow 的詳細資訊，請參閱 [Amazon MWAA 架構圖](what-is-mwaa.md#architecture-mwaa)。

**重要**  
Amazon MWAA 不會驗證客戶受管端點的 IP 地址類型 (`AddressType`) 選項，因此請務必正確指定 `AddressType`（有效選項為 IPv4 或 IPv6)。



## 在共用的 Amazon VPC 中建立環境
<a name="configure-shared-vpc"></a>

如果您使用 [AWS Organizations](https://aws.amazon.com/organizations/) 管理多個 AWS 帳戶 共用資源，您可以使用客戶管理的 VPC 端點搭配 Amazon MWAA，與您組織中的另一個帳戶共用環境資源。

當您設定共用 VPC 存取時，擁有主要 Amazon VPC (*擁有者*) 的帳戶會與屬於相同組織的其他帳戶 (*參與者*) 共用 Amazon MWAA 所需的兩個私有子網路。共用這些子網路的參與者帳戶可以檢視、建立、修改和刪除共用 Amazon VPC 中的環境。

假設您有一個帳戶 ，`Owner`做為組織中`Root`的帳戶，並擁有 Amazon VPC 資源，以及參與者帳戶 `Participant`，即同一組織的成員。當 在與 共用的 Amazon VPC 中`Participant`建立新的 Amazon MWAA 時`Owner`，Amazon MWAA 會先建立服務 VPC 資源，然後進入[https://docs.aws.amazon.com/mwaa/latest/API/API_Environment.html#mwaa-Type-Environment-Status](https://docs.aws.amazon.com/mwaa/latest/API/API_Environment.html#mwaa-Type-Environment-Status)狀態長達 72 小時。

環境狀態從 變更為 `CREATING` 後`PENDING`，代表 的委託人會`Owner`建立所需的端點。若要這樣做，Amazon MWAA 會在 Amazon MWAA 主控台中列出資料庫和 Web 伺服器端點。您也可以呼叫 []() API 動作來取得服務端點。

**注意**  
如果您用來共用資源的 Amazon VPC 是私有 Amazon VPC，您仍然必須完成中所述的步驟[在 Amazon MWAA 上管理對服務特定 Amazon VPC 端點的存取](vpc-vpe-access.md)。本主題涵蓋設定與 AWS 整合 AWS 之其他服務相關的不同 Amazon VPC 端點集，例如 Amazon ECR、Amazon ECS 和 Amazon SQS。這些服務對於在雲端中操作和管理 Apache Airflow 環境至關重要。

### 先決條件
<a name="configure-shared-vpc-prerequisites"></a>

在共用 VPC 中建立 Amazon MWAA 環境之前，您需要下列資源：
+  AWS 帳戶，`Owner`用作擁有 Amazon VPC 的帳戶。
+ [AWS Organizations](https://aws.amazon.com/organizations/) 組織單位，`MyOrganization`建立為*根*目錄。
+ 下的第二個 AWS 帳戶`Participant``MyOrganization`，為建立新環境的參與者帳戶提供服務。

此外，我們建議您熟悉在 Amazon VPC 中共用資源時[，擁有者和參與者的責任和許可](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-sharing.html#vpc-share-limitations)。

### 建立 Amazon VPC
<a name="configure-shared-vpc-create-vpc"></a>

首先，建立擁有者和參與者帳戶將共用的新 Amazon VPC：

1. 使用 登入 主控台，`Owner`然後開啟 CloudFormation 主控台。使用下列範本來建立堆疊。此堆疊會佈建多個聯網資源，包括 Amazon VPC，以及這兩個帳戶在此案例中將共用的子網路。

   ```
   AWSTemplateFormatVersion: "2010-09-09"                   
   Description: >-
   This template deploys a VPC, with a pair of public and private subnets spread across two Availability Zones. It deploys an internet gateway, with a default route on the public subnets. It deploys a pair of NAT gateways (one in each AZ), and default routes for them in the private subnets.
    Parameters:
      EnvironmentName:
        Description: An environment name that is prefixed to resource names
        Type: String
        Default: mwaa-
      VpcCIDR:
        Description: Please enter the IP range (CIDR notation) for this VPC
        Type: String
        Default: 10.192.0.0/16
      PublicSubnet1CIDR:
        Description: >-
        Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone
        Type: String
        Default: 10.192.10.0/24
      PublicSubnet2CIDR:
        Description: >-
        Please enter the IP range (CIDR notation) for the public subnet in the	second Availability Zone
        Type: String
        Default: 10.192.11.0/24
      PrivateSubnet1CIDR:
        Description: >-
        Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone
        Type: String
        Default: 10.192.20.0/24
      PrivateSubnet2CIDR:
        Description: >-
        Please enter the IP range (CIDR notation) for the private subnet in the second Availability Zone
        Type: String
        Default: 10.192.21.0/24
    Resources:
      VPC:
        Type: 'AWS::EC2::VPC'
        Properties:
        CidrBlock: !Ref VpcCIDR
        EnableDnsSupport: true
        EnableDnsHostnames: true
        Tags:
          - Key: Name
          Value: !Ref EnvironmentName
      InternetGateway:
        Type: 'AWS::EC2::InternetGateway'
        Properties:
        Tags:
          - Key: Name
          Value: !Ref EnvironmentName
      InternetGatewayAttachment:
        Type: 'AWS::EC2::VPCGatewayAttachment'
        Properties:
          InternetGatewayId: !Ref InternetGateway
          VpcId: !Ref VPC
      PublicSubnet1:
        Type: 'AWS::EC2::Subnet'
        Properties:
          VpcId: !Ref VPC
          AvailabilityZone: !Select 
            - 0
            - !GetAZs ''
          CidrBlock: !Ref PublicSubnet1CIDR
          MapPublicIpOnLaunch: true
          Tags:
            - Key: Name
            Value: !Sub '${EnvironmentName} Public Subnet (AZ1)'
      PublicSubnet2:
        Type: 'AWS::EC2::Subnet'
        Properties:
   						VpcId: !Ref VPC
          AvailabilityZone: !Select 
            - 1
            - !GetAZs ''
          CidrBlock: !Ref PublicSubnet2CIDR
          MapPublicIpOnLaunch: true
          Tags:
            - Key: Name
            Value: !Sub '${EnvironmentName} Public Subnet (AZ2)'
      PrivateSubnet1:
        Type: 'AWS::EC2::Subnet'
        Properties:
          VpcId: !Ref VPC
          AvailabilityZone: !Select 
            - 0
            - !GetAZs ''
          CidrBlock: !Ref PrivateSubnet1CIDR
          MapPublicIpOnLaunch: false
            Tags:
            - Key: Name
              Value: !Sub '${EnvironmentName} Private Subnet (AZ1)'
      PrivateSubnet2:
        Type: 'AWS::EC2::Subnet'
        Properties:
          VpcId: !Ref VPC
          AvailabilityZone: !Select 
            - 1
            - !GetAZs ''
          CidrBlock: !Ref PrivateSubnet2CIDR
          MapPublicIpOnLaunch: false
          Tags:
            - Key: Name
            Value: !Sub '${EnvironmentName} Private Subnet (AZ2)'
      NatGateway1EIP:
        Type: 'AWS::EC2::EIP'
        DependsOn: InternetGatewayAttachment
        Properties:
          Domain: vpc
      NatGateway2EIP:
        Type: 'AWS::EC2::EIP'
        DependsOn: InternetGatewayAttachment
        Properties:
          Domain: vpc
      NatGateway1:
        Type: 'AWS::EC2::NatGateway'
        Properties:
          AllocationId: !GetAtt NatGateway1EIP.AllocationId
          SubnetId: !Ref PublicSubnet1
      NatGateway2:
        Type: 'AWS::EC2::NatGateway'
        Properties:
          AllocationId: !GetAtt NatGateway2EIP.AllocationId
          SubnetId: !Ref PublicSubnet2
      PublicRouteTable:
        Type: 'AWS::EC2::RouteTable'
        Properties:
          VpcId: !Ref VPC
          Tags:
            - Key: Name
            Value: !Sub '${EnvironmentName} Public Routes'
      DefaultPublicRoute:
        Type: 'AWS::EC2::Route'
        DependsOn: InternetGatewayAttachment
        Properties:
          RouteTableId: !Ref PublicRouteTable
          DestinationCidrBlock: 0.0.0.0/0
          GatewayId: !Ref InternetGateway
      PublicSubnet1RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          RouteTableId: !Ref PublicRouteTable
          SubnetId: !Ref PublicSubnet1
      PublicSubnet2RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          RouteTableId: !Ref PublicRouteTable
          SubnetId: !Ref PublicSubnet2
      PrivateRouteTable1:
        Type: 'AWS::EC2::RouteTable'
        Properties:
          VpcId: !Ref VPC
          Tags:
            - Key: Name
            Value: !Sub '${EnvironmentName} Private Routes (AZ1)'
      DefaultPrivateRoute1:
        Type: 'AWS::EC2::Route'
        Properties:
          RouteTableId: !Ref PrivateRouteTable1
          DestinationCidrBlock: 0.0.0.0/0
          NatGatewayId: !Ref NatGateway1
      PrivateSubnet1RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          RouteTableId: !Ref PrivateRouteTable1
          SubnetId: !Ref PrivateSubnet1
      PrivateRouteTable2:
        Type: 'AWS::EC2::RouteTable'
        Properties:
          VpcId: !Ref VPC
          Tags:
            - Key: Name
            Value: !Sub '${EnvironmentName} Private Routes (AZ2)'
      DefaultPrivateRoute2:
        Type: 'AWS::EC2::Route'
        Properties:
          RouteTableId: !Ref PrivateRouteTable2
          DestinationCidrBlock: 0.0.0.0/0
          NatGatewayId: !Ref NatGateway2
      PrivateSubnet2RouteTableAssociation:
        Type: 'AWS::EC2::SubnetRouteTableAssociation'
        Properties:
          RouteTableId: !Ref PrivateRouteTable2
          SubnetId: !Ref PrivateSubnet2
      SecurityGroup:
        Type: 'AWS::EC2::SecurityGroup'
        Properties:
          GroupName: mwaa-security-group
          GroupDescription: Security group with a self-referencing inbound rule.
          VpcId: !Ref VPC
      SecurityGroupIngress:
        Type: 'AWS::EC2::SecurityGroupIngress'
        Properties:
          GroupId: !Ref SecurityGroup
          IpProtocol: '-1'
          SourceSecurityGroupId: !Ref SecurityGroup
          Outputs:
            VPC:
              Description: A reference to the created VPC
              Value: !Ref VPC
              PublicSubnets:
              Description: A list of the public subnets
              Value: !Join 
                - ','
                - - !Ref PublicSubnet1
                - !Ref PublicSubnet2
            PrivateSubnets:
              Description: A list of the private subnets
              Value: !Join 
                - ','
                - - !Ref PrivateSubnet1
                - !Ref PrivateSubnet2
            PublicSubnet1:
              Description: A reference to the public subnet in the 1st Availability Zone
              Value: !Ref PublicSubnet1
            PublicSubnet2:
              Description: A reference to the public subnet in the 2nd Availability Zone
              Value: !Ref PublicSubnet2
            PrivateSubnet1:
              Description: A reference to the private subnet in the 1st Availability Zone
              Value: !Ref PrivateSubnet1
            PrivateSubnet2:
              Description: A reference to the private subnet in the 2nd Availability Zone
              Value: !Ref PrivateSubnet2
            SecurityGroupIngress:
              Description: Security group with self-referencing inbound rule
              Value: !Ref SecurityGroupIngress
   ```

1. 佈建新的 Amazon VPC 資源後，導覽至 AWS Resource Access Manager 主控台，然後選擇**建立資源共享**。

1. 從可與 共用的可用子網路清單中，選擇您在第一個步驟中建立的子網路`Participant`。

### 建立 環境
<a name="configure-shared-vpc-create-mwaa"></a>

完成下列步驟，以使用客戶管理的 Amazon VPC 端點建立 Amazon MWAA 環境。

1. 使用 登入`Participant`，然後開啟 Amazon MWAA 主控台。完成**步驟一：指定詳細資訊**，以指定新環境的 Amazon S3 儲存貯體、DAG 資料夾和相依性。如需詳細資訊，請參閱[入門](create-environment.md#create-environment-start-details)。

1. 在**設定進階設定**頁面的**聯網**下，從共用的 Amazon VPC 選擇子網路。

1. 在**端點管理**下，從下拉式清單中選擇 **CUSTOMER**。

1. 保留頁面上其餘選項的預設值，然後在**檢閱和建立**頁面上選擇**建立環境**。

環境以 `CREATING` 狀態開始，然後變更為 `PENDING`。當環境為 時`PENDING`，請使用主控台記下**資料庫端點服務名稱**和 **Web 伺服器端點服務名稱** （如果您設定私有 Web 伺服器）。

當您使用 Amazon MWAA 主控台建立新環境時。Amazon MWAA 會使用必要的傳入和傳出規則建立新的安全群組。記下該安全群組 ID。

在下一節中， `Owner`將使用服務端點和安全群組 ID 在共用的 Amazon VPC 中建立新的 Amazon VPC 端點。

### 建立 Amazon VPC 端點
<a name="configure-shared-vpc-create-endpoints"></a>

完成下列步驟，為您的環境建立所需的 Amazon VPC 端點。

1.  AWS 管理主控台 使用 登入 `Owner`，開啟 https：//[https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/)。

1. 從左側導覽面板中選擇**安全群組**，然後使用下列傳入和傳出規則，在共用的 Amazon VPC 中建立新的安全群組：    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/mwaa/latest/userguide/vpc-endpoint-management.html)
**警告**  
`Owner` 帳戶必須在`Owner`帳戶中設定安全群組，以允許從新環境到共用 Amazon VPC 的流量。您可以在 中建立新的安全群組`Owner`，或編輯現有的安全群組。

1. 選擇**端點**，然後使用先前步驟中的端點服務名稱，為環境資料庫和 Web 伺服器 （如果處於私有模式） 建立新的端點。選擇共用的 Amazon VPC、您用於環境的子網路，以及環境的安全群組。

如果成功，環境將從`PENDING`返回 變更為 `CREATING`，最後變更為 `AVAILABLE`。當它是 時`AVAILABLE`，您可以登入 Apache Airflow 主控台。

### 共用 Amazon VPC 故障診斷
<a name="configure-shared-vpc-troubleshooting"></a>

使用以下參考來解決在共用 Amazon VPC 中建立環境時遇到的問題。

**`PENDING` 狀態`CREATE_FAILED`後 中的環境**  
+ 驗證 `Owner` 是否`Participant`使用 與 共用子網路[AWS Resource Access Manager](https://docs.aws.amazon.com/ram/latest/userguide/what-is.html)。
+ 確認資料庫和 Web 伺服器的 Amazon VPC 端點是在與環境相關聯的相同子網路中建立。
+ 確認與端點搭配使用的安全群組允許來自環境所用安全群組的流量。`Owner` 帳戶會建立將 中安全群組參考`Participant`為 的規則`{{123456789012}}/{{security-group-id}}`：。    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/mwaa/latest/userguide/vpc-endpoint-management.html)

  如需詳細資訊，請參閱[擁有者和參與者的責任和許可](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-sharing.html#vpc-share-limitations)

**環境卡在 `PENDING` 狀態**  
驗證每個 VPC 端點狀態，以確保其為 `Available`。如果您使用私有 Web 伺服器設定環境，您還必須為 Web 伺服器建立端點。如果環境卡在 中`PENDING`，這可能表示私有 Web 伺服器端點遺失。

**收到`The Vpc Endpoint Service '{{vpce-service-name}}' does not exist`錯誤**  
如果您參考下列錯誤，請確認在擁有共用 VPC 的帳戶中建立端點`Owner`的帳戶：  

```
ClientError: An error occurred (InvalidServiceName) when calling the CreateVpcEndpoint operation: 
							
The Vpc Endpoint Service '{{vpce-service-name}}' does not exist
```