

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Rekan dengan VPC di yang lain Akun AWS
<a name="peer-with-vpc-in-another-account"></a>

Anda dapat mengintip dengan Virtual Private Cloud (VPC) di tempat lain dengan menggunakan. Akun AWS [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-vpcpeeringconnection.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-vpcpeeringconnection.html) Ini menciptakan koneksi jaringan antara dua VPCs yang memungkinkan Anda untuk mengarahkan lalu lintas di antara mereka sehingga mereka dapat berkomunikasi seolah-olah mereka berada dalam jaringan yang sama. Koneksi peering VPC dapat membantu memfasilitasi akses data dan transfer data.

Untuk membuat koneksi peering VPC, Anda perlu mengotorisasi dua terpisah Akun AWS dalam satu tumpukan. CloudFormation 

Untuk informasi selengkapnya tentang peering VPC dan batasannya, lihat Panduan Peering [VPC](https://docs.aws.amazon.com/vpc/latest/peering/) Amazon. 

## Prasyarat
<a name="peer-with-vpc-in-another-account-prerequisites"></a>

1. Anda memerlukan ID VPC peer, ID Akun AWS rekan, dan peran [akses lintas akun untuk](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_common-scenarios_aws-accounts.html) koneksi peering. 
**catatan**  
Panduan ini mengacu pada dua akun: Pertama adalah akun yang memungkinkan peering lintas akun (*akun penerima*). Kedua adalah akun yang meminta koneksi peering (*akun peminta*).

1. Untuk menerima koneksi peering VPC, peran akses lintas-akun harus dapat Anda tanggung. Sumber daya berperilaku dengan cara yang sama seperti sumber daya koneksi peering VPC di akun yang sama. *Untuk informasi tentang cara administrator IAM memberikan izin untuk mengambil peran lintas akun, lihat [Memberikan izin pengguna untuk beralih peran dalam Panduan Pengguna](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_permissions-to-switch.html) IAM.*

## Langkah 1: Buat VPC dan peran lintas akun
<a name="step-1-create-vpc-and-cross-account-role"></a>

Di langkah ini, Anda akan membuat VPC dan peran dalam *akun penerima*.

**Untuk membuat VPC dan peran akses lintas akun**

1. Masuk ke Konsol Manajemen AWS dan buka CloudFormation konsol di [https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/).

1. Dari halaman **Stacks**, pilih **Buat tumpukan** di kanan atas, lalu pilih **Dengan sumber daya baru (standar)**.

1. **Untuk **Prasyarat - Siapkan templat**, pilih **Pilih templat yang ada** lalu **Unggah file templat, Pilih file**.**

1. Buka editor teks di mesin lokal Anda dan tambahkan salah satu templat berikut. Simpan file dan kembali ke konsol untuk memilihnya sebagai file template.  
**Example JSON**  

   ```
   {
     "AWSTemplateFormatVersion": "2010-09-09",
     "Description": "Create a VPC and an assumable role for cross account VPC peering.",
     "Parameters": {
       "PeerRequesterAccountId": {
         "Type": "String"
       }
     },
     "Resources": {
       "vpc": {
         "Type": "AWS::EC2::VPC",
         "Properties": {
           "CidrBlock": "10.1.0.0/16",
           "EnableDnsSupport": false,
           "EnableDnsHostnames": false,
           "InstanceTenancy": "default"
         }
       },
       "peerRole": {
         "Type": "AWS::IAM::Role",
         "Properties": {
           "AssumeRolePolicyDocument": {
             "Statement": [
               {
                 "Principal": {
                   "AWS": {
                     "Ref": "PeerRequesterAccountId"
                   }
                 },
                 "Action": [
                   "sts:AssumeRole"
                 ],
                 "Effect": "Allow"
               }
             ]
           },
           "Path": "/",
           "Policies": [
             {
               "PolicyName": "root",
               "PolicyDocument": {
                 "Version": "2012-10-17",		 	 	 
                 "Statement": [
                   {
                     "Effect": "Allow",
                     "Action": "ec2:AcceptVpcPeeringConnection",
                     "Resource": "*"
                   }
                 ]
               }
             }
           ]
         }
       }
     },
     "Outputs": {
       "VPCId": {
         "Value": {
           "Ref": "vpc"
         }
       },
       "RoleARN": {
         "Value": {
           "Fn::GetAtt": [
             "peerRole",
             "Arn"
           ]
         }
       }
     }
   }
   ```  
**Example YAML**  

   ```
   AWSTemplateFormatVersion: 2010-09-09
   Description: Create a VPC and an assumable role for cross account VPC peering.
   Parameters:
     PeerRequesterAccountId:
       Type: String
   Resources:
     vpc:
       Type: AWS::EC2::VPC
       Properties:
         CidrBlock: 10.1.0.0/16
         EnableDnsSupport: false
         EnableDnsHostnames: false
         InstanceTenancy: default
     peerRole:
       Type: AWS::IAM::Role
       Properties:
         AssumeRolePolicyDocument:
           Statement:
             - Principal:
                 AWS: !Ref PeerRequesterAccountId
               Action:
                 - 'sts:AssumeRole'
               Effect: Allow
         Path: /
         Policies:
           - PolicyName: root
             PolicyDocument:
               Version: 2012-10-17 		 	 	 
               Statement:
                 - Effect: Allow
                   Action: 'ec2:AcceptVpcPeeringConnection'
                   Resource: '*'
   Outputs:
     VPCId:
       Value: !Ref vpc
     RoleARN:
       Value: !GetAtt 
         - peerRole
         - Arn
   ```

1. Pilih **Berikutnya**.

1. Beri nama tumpukan (misalnya,**VPC-owner**), lalu masukkan Akun AWS ID *akun pemohon* di **PeerRequesterAccountId**bidang.

1. Terima default, dan kemudian pilih **Selanjutnya**.

1. Pilih **Saya mengakui yang CloudFormation mungkin membuat sumber daya IAM**, lalu pilih **Buat** tumpukan.

## Langkah 2: Buat templat yang mencakup `AWS::EC2::VPCPeeringConnection`
<a name="step-2-create-template-for-vpc-peering-connection-owner"></a>

*Sekarang setelah Anda membuat VPC dan peran lintas akun, Anda dapat mengintip VPC menggunakan yang lain Akun AWS (akun pemohon).*

**Untuk membuat template yang menyertakan sumber daya [AWS: :EC2:: VPCPeering](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-ec2-vpcpeeringconnection.html) Connection**

1. Kembali ke halaman beranda CloudFormation konsol.

1. Dari halaman **Stacks**, pilih **Buat tumpukan** di kanan atas, lalu pilih **Dengan sumber daya baru (standar)**.

1. **Untuk **Prasyarat - Siapkan templat**, pilih **Pilih templat yang ada** lalu **Unggah file templat, Pilih file**.**

1. Buka editor teks di mesin lokal Anda dan tambahkan salah satu templat berikut. Simpan file dan kembali ke konsol untuk memilihnya sebagai file template.  
**Example JSON**  

   ```
   {
     "AWSTemplateFormatVersion": "2010-09-09",
     "Description": "Create a VPC and a VPC Peering connection using the PeerRole to accept.",
     "Parameters": {
       "PeerVPCAccountId": {
         "Type": "String"
       },
       "PeerVPCId": {
         "Type": "String"
       },
       "PeerRoleArn": {
         "Type": "String"
       }
     },
     "Resources": {
       "vpc": {
         "Type": "AWS::EC2::VPC",
         "Properties": {
           "CidrBlock": "10.2.0.0/16",
           "EnableDnsSupport": false,
           "EnableDnsHostnames": false,
           "InstanceTenancy": "default"
         }
       },
       "vpcPeeringConnection": {
         "Type": "AWS::EC2::VPCPeeringConnection",
         "Properties": {
           "VpcId": {
             "Ref": "vpc"
           },
           "PeerVpcId": {
             "Ref": "PeerVPCId"
           },
           "PeerOwnerId": {
             "Ref": "PeerVPCAccountId"
           },
           "PeerRoleArn": {
             "Ref": "PeerRoleArn"
           }
         }
       }
     },
     "Outputs": {
       "VPCId": {
         "Value": {
           "Ref": "vpc"
         }
       },
       "VPCPeeringConnectionId": {
         "Value": {
           "Ref": "vpcPeeringConnection"
         }
       }
     }
   }
   ```  
**Example YAML**  

   ```
   AWSTemplateFormatVersion: 2010-09-09
   Description: Create a VPC and a VPC Peering connection using the PeerRole to accept.
   Parameters:
     PeerVPCAccountId:
       Type: String
     PeerVPCId:
       Type: String
     PeerRoleArn:
       Type: String
   Resources:
     vpc:
       Type: AWS::EC2::VPC
       Properties:
         CidrBlock: 10.2.0.0/16
         EnableDnsSupport: false
         EnableDnsHostnames: false
         InstanceTenancy: default
     vpcPeeringConnection:
       Type: AWS::EC2::VPCPeeringConnection
       Properties:
         VpcId: !Ref vpc
         PeerVpcId: !Ref PeerVPCId
         PeerOwnerId: !Ref PeerVPCAccountId
         PeerRoleArn: !Ref PeerRoleArn
   Outputs:
     VPCId:
       Value: !Ref vpc
     VPCPeeringConnectionId:
       Value: !Ref vpcPeeringConnection
   ```

1. Pilih **Berikutnya**.

1. Beri nama tumpukan (misalnya, **VPC-peering-connection**).

1. Terima default, dan kemudian pilih **Selanjutnya**.

1. Pilih **Saya mengakui yang CloudFormation mungkin membuat sumber daya IAM**, lalu pilih **Buat** tumpukan.

## Buat template dengan kebijakan yang sangat ketat
<a name="create-template-with-highly-restrictive-policy"></a>

Anda mungkin ingin membuat kebijakan yang sangat ketat untuk mengintip VPC Anda dengan yang lain. Akun AWS

Contoh templat berikut menunjukkan bagaimana mengubah templat pemilik peer VPC (*akun penerima* yang dibuat di Langkah 1 di atas) sehingga lebih ketat.

**Example JSON**  

```
{
  "AWSTemplateFormatVersion":"2010-09-09",
  "Description":"Create a VPC and an assumable role for cross account VPC peering.",
  "Parameters":{
    "PeerRequesterAccountId":{
      "Type":"String"
    }
  },
  "Resources":{
    "peerRole":{
      "Type":"AWS::IAM::Role",
      "Properties":{
        "AssumeRolePolicyDocument":{
          "Statement":[
            {
              "Action":[
                "sts:AssumeRole"
              ],
              "Effect":"Allow",
              "Principal":{
                "AWS":{
                  "Ref":"PeerRequesterAccountId"
                }
              }
            }
          ]
        },
        "Path":"/",
        "Policies":[
          {
            "PolicyDocument":{
              "Statement":[
                {
                  "Action":"ec2:acceptVpcPeeringConnection",
                  "Effect":"Allow",
                  "Resource":{
                    "Fn::Sub":"arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc/${vpc}"
                  }
                },
                {
                  "Action":"ec2:acceptVpcPeeringConnection",
                  "Condition":{
                    "StringEquals":{
                      "ec2:AccepterVpc":{
                        "Fn::Sub":"arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc/${vpc}"
                      }
                    }
                  },
                  "Effect":"Allow",
                  "Resource":{
                    "Fn::Sub":"arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc-peering-connection/*"
                  }
                }
              ],
              "Version":"2012-10-17" 		 	 	 
            },
            "PolicyName":"root"
          }
        ]
      }
    },
    "vpc":{
      "Type":"AWS::EC2::VPC",
      "Properties":{
        "CidrBlock":"10.1.0.0/16",
        "EnableDnsHostnames":false,
        "EnableDnsSupport":false,
        "InstanceTenancy":"default"
      }
    }
  },
  "Outputs":{
    "RoleARN":{
      "Value":{
        "Fn::GetAtt":[
          "peerRole",
          "Arn"
        ]
      }
    },
    "VPCId":{
      "Value":{
        "Ref":"vpc"
      }
    }
  }
}
```

**Example YAML**  

```
AWSTemplateFormatVersion: 2010-09-09
Description: Create a VPC and an assumable role for cross account VPC peering.
Parameters:
  PeerRequesterAccountId:
    Type: String
Resources:
  peerRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Action:
              - 'sts:AssumeRole'
            Effect: Allow
            Principal:
              AWS:
                Ref: PeerRequesterAccountId
      Path: /
      Policies:
        - PolicyDocument:
            Statement:
              - Action: 'ec2:acceptVpcPeeringConnection'
                Effect: Allow
                Resource:
                  'Fn::Sub': 'arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc/${vpc}'
              - Action: 'ec2:acceptVpcPeeringConnection'
                Condition:
                  StringEquals:
                    'ec2:AccepterVpc':
                      'Fn::Sub': 'arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc/${vpc}'
                Effect: Allow
                Resource:
                  'Fn::Sub': >-
                    arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:vpc-peering-connection/*
            Version: 2012-10-17 		 	 	 
          PolicyName: root
  vpc:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.1.0.0/16
      EnableDnsHostnames: false
      EnableDnsSupport: false
      InstanceTenancy: default
Outputs:
  RoleARN:
    Value:
      'Fn::GetAtt':
        - peerRole
        - Arn
  VPCId:
    Value:
      Ref: vpc
```

Untuk mengakses VPC, Anda dapat menggunakan templat peminta yang sama seperti pada Langkah 2 di atas.

Untuk informasi selengkapnya, lihat [Identitas dan manajemen akses untuk mengintip VPC di Panduan Peering](https://docs.aws.amazon.com/vpc/latest/peering/security-iam.html) *VPC* Amazon.