Amazon web services cnf init在ubuntu ami上抛出Python错误
我正在使用下面的aws cloudformation模板来启动一个自动缩放组,当我尝试运行cfn init时,它抛出了一个python错误。我已经想尽一切办法来解决这个问题,但现在我完全被难倒了。我得到的错误是: 生成期间发生错误:列表索引必须是整数,而不是unicode 这是我的Cloudformation模板: Description: 'Autoscaling groups' Parameters: DeploymentProfileARN: Description: The ARN of the iam group with deployment permissions. Type: String PublicSecurityGroup: Description: The security group for use with ec2. Type: String TargetGroup: Description: The load balancer target group Type: String Subnets: Description: The load balancer target group Type: 'List<AWS::EC2::Subnet::Id>' DomainUrl: Description: The url of the site excluding any sub domains eg. "example.com" Type: String EnvironmentName: Description: An environment name that will be prefixed to resource names Type: String Default: Dev AllowedValues: [Prod, Uat, Dev] MasterDataBaseAddress: Description: The address of the master database Type: String Resources: AuthScalingLaunchConfig: Type: AWS::AutoScaling::LaunchConfiguration Metadata: AWS::CloudFormation::Init: nginx: packages: apt: - "nginx-core" files: '/tmp/test': content: !Sub | test '/etc/nginx/sites-enabled/default': content: !Sub | upstream phoenix { server 127.0.0.1:4000 max_fails=5 fail_timeout=60s; } server { listen 80 default_server; server_name .${DomainUrl}; location / { allow all; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Cluster-Client-Ip $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://phoenix; } } commands: 01-restartNginx: command: service nginx restart configSets: setup: - "nginx" Properties: ImageId: "ami-0701e7be9b2a77600" InstanceType: t1.micro KeyName: "main" IamInstanceProfile: !Ref DeploymentProfileARN SecurityGroups: - !Ref PublicSecurityGroup UserData: Fn::Base64: !Sub | #!/bin/bash # install cfn apt update apt install -y python-pip mkdir -p /opt/aws/bin pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gpip cfn-init --stack ${AWS::StackName} --resource AuthScalingLaunchConfig --region ${AWS::Region} --configsets setup service cfn-hup start AutoScalingGroup: Type: AWS::AutoScaling::AutoScalingGroup Properties: AvailabilityZones: - !Select [ 0, !GetAZs "" ] - !Select [ 1, !GetAZs "" ] LaunchConfigurationName: !Ref AuthScalingLaunchConfig TargetGroupARNs: - !Ref TargetGroup HealthCheckGracePeriod: "60" HealthCheckType: EC2 VPCZoneIdentifier: !Ref Subnets MaxSize: "10" DesiredCapacity: "1" MinSize: "1" 描述:“自动缩放组” 参数: DeploymentProfileARN: 描述:具有部署权限的iam组的ARN。 类型:字符串 公共安全组: 描述:用于ec2的安全组。 类型:字符串 目标群体: 描述:负载平衡器目标组 类型:字符串 子网: 描述:负载平衡器目标组 键入:“列表” 域名URL: 描述:网站的url,不包括任何子域,如“example.com” 类型:字符串 环境名称: 描述:将作为资源名称前缀的环境名称 类型:字符串 默认值:Dev 允许值:[Prod、Uat、Dev] 主数据库地址: 描述:主数据库的地址 类型:字符串 资源: AuthScalingLaunchConfig: 类型:AWS::AutoScaling::LaunchConfiguration 元数据: AWS::CloudFormation::Init: nginx: 包装: 恰当的: -“nginx核心” 文件夹: “/tmp/test”: 内容:!潜艇| 测试 “/etc/nginx/sites enabled/default”: 内容:!潜艇| 上游凤凰城{ 服务器127.0.0.1:4000最大故障数=5故障超时时间=60s; } 服务器{ 监听80个默认_服务器; 服务器名称。${DomainUrl}; 地点/{ 允许一切; proxy_http_版本1.1; proxy\u set\u header X-Forwarded-For$proxy\u add\u X\u Forwarded\u For; 代理设置头主机$http\U主机; 代理集头X-Cluster-Client-Ip$remote\u addr; 代理设置头升级$http\U升级; 代理设置头连接“升级”; 代理通行证http://phoenix; } } 命令: 01 restartNginx: 命令:服务nginx restart 配置集: 设置: -“nginx” 特性: 图像ID:“ami-0701e7be9b2a77600” 实例类型:t1.micro 关键字名称:“主” IAMSInstanceProfile:!参考DeploymentProfileARN 安全组: - !Ref公共安全集团 用户数据: Fn::Base64:!潜艇| #!/bin/bash #安装cfn apt更新 apt安装-y python pip mkdir-p/opt/aws/bin pip安装https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gpip cfn init--堆栈${AWS::StackName}--资源AuthScalingLaunchConfig--区域${AWS::region}--配置集设置 服务cfn hup启动 自动缩放组: 类型:AWS::AutoScaling::AutoScalingGroup 特性: 可用区域: - !选择[0,!GetAZs”“] - !选择[1,!GetAZs”“] LaunchConfigurationName:!参考AuthScalingLaunchConfig TargetGroupARNs: - !参考目标群 HealthCheckGracePeriod:“60” HealthCheckType:EC2 VPCZoneIdentifier:!参考子网 最大尺寸:“10” 所需容量:“1” MinSize:“1”Amazon web services cnf init在ubuntu ami上抛出Python错误,amazon-web-services,ubuntu,pip,amazon-cloudformation,Amazon Web Services,Ubuntu,Pip,Amazon Cloudformation,我正在使用下面的aws cloudformation模板来启动一个自动缩放组,当我尝试运行cfn init时,它抛出了一个python错误。我已经想尽一切办法来解决这个问题,但现在我完全被难倒了。我得到的错误是: 生成期间发生错误:列表索引必须是整数,而不是unicode 这是我的Cloudformation模板: Description: 'Autoscaling groups' Parameters: DeploymentProfileARN: Description: Th
在正确的方向上提供任何帮助或指导都将是了不起的。我尝试过使用不同版本的aws cfn引导,但它们都给了我相同的问题。我对UserData做了以下更改,将获得最新的cfn init
Description: 'Autoscaling groups'
Parameters:
DeploymentProfileARN:
Description: The ARN of the iam group with deployment permissions.
Type: String
PublicSecurityGroup:
Description: The security group for use with ec2.
Type: String
TargetGroup:
Description: The load balancer target group
Type: String
Subnets:
Description: The load balancer target group
Type: 'List<AWS::EC2::Subnet::Id>'
DomainUrl:
Description: The url of the site excluding any sub domains eg. "example.com"
Type: String
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
Default: Dev
AllowedValues: [Prod, Uat, Dev]
MasterDataBaseAddress:
Description: The address of the master database
Type: String
Resources:
AuthScalingLaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
nginx:
packages:
apt:
- "nginx-core"
files:
'/tmp/test':
content: !Sub |
test
'/etc/nginx/sites-enabled/default':
content: !Sub |
upstream phoenix {
server 127.0.0.1:4000 max_fails=5 fail_timeout=60s;
}
server {
listen 80 default_server;
server_name .${DomainUrl};
location / {
allow all;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Cluster-Client-Ip $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://phoenix;
}
}
commands:
01-restartNginx:
command: service nginx restart
configSets:
setup:
- "nginx"
Properties:
ImageId: "ami-0701e7be9b2a77600"
InstanceType: t1.micro
KeyName: "main"
IamInstanceProfile: !Ref DeploymentProfileARN
SecurityGroups:
- !Ref PublicSecurityGroup
UserData:
Fn::Base64:
!Sub
- |
#!/bin/bash
# install cfn
apt-get update -y
apt-get install -y python-pip curl gzip python3-pip
pip install awscli --upgrade
pip install --upgrade pip
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade awscli
cd ~
if [ ! -d ~/aws-cfn-bootstrap-latest ]; then
apt-get install -y python-setuptools jq
# Get the latest CloudFormation package
cd ~
mkdir aws-cfn-bootstrap-latest
curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
easy_install aws-cfn-bootstrap-latest
fi
# Run CFN-Init
echo "cfn-init starting" 2>&1;
/usr/local/bin/cfn-init -s ${AWS::StackId} -r AuthScalingLaunchConfig --region ${AWS::Region} -c setup
echo "cfn-init complete" 2>&1;
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones:
- !Select [ 0, !GetAZs "" ]
- !Select [ 1, !GetAZs "" ]
LaunchConfigurationName: !Ref AuthScalingLaunchConfig
TargetGroupARNs:
- !Ref TargetGroup
HealthCheckGracePeriod: "60"
HealthCheckType: EC2
VPCZoneIdentifier: !Ref Subnets
MaxSize: "10"
DesiredCapacity: "1"
MinSize: "1"
说明:“自动缩放组”
参数:
DeploymentProfileARN:
描述:具有部署权限的iam组的ARN。
类型:字符串
公共安全组:
描述:用于ec2的安全组。
类型:字符串
目标群体:
描述:负载平衡器目标组
类型:字符串
子网:
描述:负载平衡器目标组
键入:“列表”
域名URL:
描述:网站的url,不包括任何子域,如“example.com”
类型:字符串
环境名称:
描述:将作为资源名称前缀的环境名称
类型:字符串
默认值:Dev
允许值:[Prod、Uat、Dev]
主数据库地址:
描述:主数据库的地址
类型:字符串
资源:
AuthScalingLaunchConfig:
类型:AWS::AutoScaling::LaunchConfiguration
元数据:
AWS::CloudFormation::Init:
nginx:
包装:
恰当的:
-“nginx核心”
文件夹:
“/tmp/test”:
内容:!潜艇|
测试
“/etc/nginx/sites enabled/default”:
内容:!潜艇|
上游凤凰城{
服务器127.0.0.1:4000最大故障数=5故障超时时间=60s;
}
服务器{
监听80个默认_服务器;
服务器名称。${DomainUrl};
地点/{
允许一切;
proxy_http_版本1.1;
proxy\u set\u header X-Forwarded-For$proxy\u add\u X\u Forwarded\u For;
代理设置头主机$http\U主机;
代理集头X-Cluster-Client-Ip$remote\u addr;
代理设置头升级$http\U升级;
代理设置头连接“升级”;
代理通行证http://phoenix;
}
}
命令:
01 restartNginx:
命令:服务nginx restart
配置集:
设置:
Description: 'Autoscaling groups'
Parameters:
DeploymentProfileARN:
Description: The ARN of the iam group with deployment permissions.
Type: String
PublicSecurityGroup:
Description: The security group for use with ec2.
Type: String
TargetGroup:
Description: The load balancer target group
Type: String
Subnets:
Description: The load balancer target group
Type: 'List<AWS::EC2::Subnet::Id>'
DomainUrl:
Description: The url of the site excluding any sub domains eg. "example.com"
Type: String
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
Default: Dev
AllowedValues: [Prod, Uat, Dev]
MasterDataBaseAddress:
Description: The address of the master database
Type: String
Resources:
AuthScalingLaunchConfig:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
AWS::CloudFormation::Init:
nginx:
packages:
apt:
'nginx-core': []
files:
'/etc/nginx/sites-enabled/default':
content: !Sub |
upstream phoenix {
server 127.0.0.1:4000 max_fails=5 fail_timeout=60s;
}
server {
listen 80 default_server;
server_name .${DomainUrl};
location / {
allow all;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Cluster-Client-Ip $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://phoenix;
}
}
commands:
01-restartNginx:
command: service nginx restart
configSets:
setup:
- "nginx"
Properties:
ImageId: "ami-0701e7be9b2a77600"
InstanceType: t1.micro
KeyName: "main"
IamInstanceProfile: !Ref DeploymentProfileARN
SecurityGroups:
- !Ref PublicSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
# install cfn
apt-get -y update
apt-get -y install python-pip
pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
cp /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup
chmod +x /etc/init.d/cfn-hup
update-rc.d cfn-hup defaults
service cfn-hup start
# install code deploy
cd /home/ubuntu
wget https://aws-codedeploy-eu-west-1.s3.amazonaws.com/latest/install
chmod +x ./install
./install auto
cfn-init --stack ${AWS::StackName} --resource AuthScalingLaunchConfig --region ${AWS::Region} --configsets setup
RibbonAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AvailabilityZones:
- !Select [ 0, !GetAZs "" ]
- !Select [ 1, !GetAZs "" ]
LaunchConfigurationName: !Ref AuthScalingLaunchConfig
TargetGroupARNs:
- !Ref TargetGroup
HealthCheckGracePeriod: "60"
HealthCheckType: EC2
VPCZoneIdentifier: !Ref Subnets
MaxSize: "10"
DesiredCapacity: "1"
MinSize: "1"