我正在尝试使用Elastic Beanstalk的T2 Unlimited实例。实例启动后我不想配置它,所以我想知道是否有人知道EB配置是否完全可能?
我找到了解决方案。如果其他人遇到同样的问题,请将其发布在此处:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InstanceCreditPolicy",
"Effect": "Allow",
"Action": [
"ec2:ModifyInstanceCreditSpecification",
"ec2:DescribeInstanceCreditSpecifications"
],
"Resource": "*"
}
]
}
.ebextensions/01-set-instance-credit-unlimited.config
)commands:
set-instance-credit-unlimited:
command: |
aws ec2 modify-instance-credit-specification --region <your_region> --instance-credit-specification '[{"InstanceId": "'"$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)"'","CpuCredits": "unlimited"}]'
如果您正在使用解决方案堆栈 - “运行Node.js的64位Amazon Linux 2017.03 v4.1.1”,除了创建用户steinim描述的策略之外,您还需要使用这两个配置文件:
1)upgrade-awscli.config
commands:
modify-instance-credit-specification:
command: "sudo pip install --upgrade awscli"
2)t2-unlimited-test.config
commands:
modify-instance-credit-specification:
command: "aws ec2 modify-instance-credit-specification --region us-west-2 --instance-credit-specification '[{\"InstanceId\": \"'\"$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)\"'\",\"CpuCredits\": \"unlimited\"}]'"
对于任何寻找@ steinim答案的PowerShell版本的人来说,就是这样:
$InstanceID = wget http://169.254.169.254/latest/meta-data/instance-id -UseBasicParsing
$Credit = New-Object -TypeName Amazon.EC2.Model.InstanceCreditSpecificationRequest
$Credit.InstanceId = $InstanceID
$Credit.CpuCredits = "unlimited"
Edit-EC2InstanceCreditSpecification -InstanceCreditSpecification $Credit
所以你的.ebextensions/01-set-instance-credit-unlimited.config
文件看起来像这样:
files:
"c:/scripts/Enable-T2Unlimited.ps1":
content: |
Import-Module AWSPowerShell
$InstanceID = wget http://169.254.169.254/latest/meta-data/instance-id -UseBasicParsing
$Credit = New-Object -TypeName Amazon.EC2.Model.InstanceCreditSpecificationRequest
$Credit.InstanceId = $InstanceID
$Credit.CpuCredits = "unlimited"
Edit-EC2InstanceCreditSpecification -InstanceCreditSpecification $Credit
commands:
01_Enable_T2_Unlimited:
command: powershell c:\\scripts\\Enable-T2Unlimited.ps1
ignoreErrors: false
waitAfterCompletion: 0