4

EIP分配給VPC的自動配置功能組我想我分配在VPC保留彈性IP的(EC2經典IP)來自動配置功能組中的一個。使用AWS CLI的我搬到IP到VPC:如何Cloudformation模板

$ aws ec2 move-address-to-vpc --public-ip 23.23.23.23 

而且在AWS檢測控制檯看到,該IP傳遞到VPC。 並在Cloudformation模板AutoscalingGroup的標籤分配中的資源:

"Process": { 
     "Type" : "AWS::AutoScaling::AutoScalingGroup", 
     "Properties": { 
      "LaunchConfigurationName": {"Ref": "PreprocessorLC"}, 
      "LoadBalancerNames": [{"Ref": "ProcessELB"}], 
      "VPCZoneIdentifier" : [{ "Fn::Join" : [",", [ { "Ref" : "PublicSubnet1"}, { "Ref" : "PublicSubnet2"} ]]}], 
      "AvailabilityZones": {"Ref": "AZs"}, 
      "MinSize" : "1", 
      "MaxSize" : "1", 
      "HealthCheckGracePeriod": 300, 
      "Tags" : [ 
       {"Key": "Name", "Value": {"Fn::Join": ["", [{"Ref": "Env"}, "-Process"]]}, "PropagateAtLaunch": true}, 
       {"Key": "WorkersScalingGroup", "Value": {"Fn::Join": ["", ["Offering-", {"Ref": "Env"}, "-Process-Worker"]]}, "PropagateAtLaunch": true}, 
       {"Key": "EIP", "Value": {"Ref": "ProcessIP"}, "PropagateAtLaunch": true}, 
       {"Key": "Environment", "Value": {"Ref": "Env"}, "PropagateAtLaunch": true} 
      ] 
     } 
    } 

而在參數 「ProcessIP」 增值:

"ProcessIP":{ 
      "Description": "DEV: 23.23.23.23", 
      "Type": "String", 
      "Default": "23.23.23.23", 
      "AllowedValues": ["23.23.23.23"] 
} 

而且它並沒有奏效。仍然獲得隨機IP。 如果有人可以知道我錯了什麼,或者應該添加什麼來使它工作?

謝謝!

回答

5

下面是簡單的bash腳本:

#!/bin/sh 
# Region in Which instance is running 
EC2_REGION='us-east-1' 
AWS_ACCESS_KEY='xxxxxxxxxxxx' 
AWS_SECRET_ACCESS_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 

#Instance ID captured through Instance meta data 
InstanceID=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id` 

#Elastic IP captured through the EIP instance tag 
Elastic_IP=`/opt/aws/apitools/ec2/bin/ec2-describe-tags -O $AWS_ACCESS_KEY -W $AWS_SECRET_ACCESS_KEY --filter resource-id=$InstanceID --filter key='EIP' | cut -f5` 
Allocate_ID=`/opt/aws/apitools/ec2/bin/ec2-describe-tags -O $AWS_ACCESS_KEY -W $AWS_SECRET_ACCESS_KEY --filter resource-id=$InstanceID --filter key="AllocationID" | cut -f5` 

#Assigning Elastic IP to Instance 
aws ec2 associate-address --instance-id $InstanceID --allocation-id $Allocate_ID 
+0

有關aws論壇上類似方法的討論https://forums.aws.amazon.com/message.jspa?messageID=498761 – Vorsprung

2

你需要明確的彈性IP地址與您所需的EC2實例相關聯。您可以在啓動時在用戶數據腳本中執行此操作,也可以通過其他腳本或配置管理進行外部操作。

PropagateAtLaunch簡單地傳播從自動縮放組標記被啓動,並作爲自動縮放動作而產生的任何情況。我不知道任何可能導致標記的彈性IP地址與啓動的實例關聯的魔法。

查看更多的討論,並與生態工業園here發射時間腳本的例子。

+0

沒有VPC它工作得很好把它放在標籤。您是否知道有關此特定問題的任何「腳本或配置管理」示例? – muzafarow

+1

一個例子:https://github.com/skymill/aws-ec2-assign-elastic-ip – jarmod

+0

順便說一句,我很感興趣地聽到,這部作品在EC2經典。我以前沒有見過。你確定沒有腳本可能會在那裏發生。 – jarmod

相關問題