Error parsing metadata commands (server). Check JSON structure and network connectivity (NAT instance or Proxy)' for uniqueId

huangapple go评论51阅读模式
英文:

Error parsing metadata commands (server). Check JSON structure and network connectivity (NAT instance or Proxy)' for uniqueId

问题

I am trying to deploy AWS Spot Fleet via CloudFormation, and I want the commands in metadata to run after the instance is up, but I got this message:

"Error parsing metadata commands (server). Check JSON structure and network connectivity (NAT instance or Proxy)" for uniqueId: ip-10-28-6-6.

What is wrong with my JSON template file?

"MyServer": {
    "Type": "AWS::EC2::SpotFleet",
    "Properties": {
        "SpotFleetRequestConfigData": {
            "IamFleetRole": "arn:aws:iam::6******2:role/aws-ec2-spot-fleet-tagging-role",
            "SpotPrice": "0.15",
            "TargetCapacity": "1",
            "LaunchSpecifications": [
                {
                    "EbsOptimized": "false",
                    "InstanceType": {
                        "Ref": "myInstanceType"
                    },
                    "ImageId": ".....",
                    "SecurityGroups": [
                        ......
                    ],
                    "SubnetId": {
                        "Ref": "mySubnet"
                    },
                    "WeightedCapacity": "1",
                    "UserData": {
                        "Fn::Base64": {
                            "Fn::Join": [
                                "",
                                [
                                    .....
                                ]
                            ]
                        }
                    }
                }
            ]
        }
    },
    "Metadata": {
        "AWS::CloudFormation::Init": {
            "commands": [
                {
                    "Fn::Join": [
                        "",
                        [
                            "echo ls -l /var/log > /home/MyFile.txt \n",
                            "chmod 777 /var/log \n"
                        ]
                    ]
                }
            ]
        }
    }
}

Thanks for the help!

英文:

i am trying to deploy AWS spot::Fleet
via cloud formation
and i want the commands in metadata will run after the instance is up.
but got this msg:

> Error parsing metadata commands (server). Check JSON structure and
> network connectivity (NAT instance or Proxy)' for uniqueId:
> ip-10-28-6-6

what is wrong with my JSON template file?

"MyServer": {
			"Type": "AWS::EC2::SpotFleet",
			"Properties": {
				"SpotFleetRequestConfigData": {
					"IamFleetRole": "arn:aws:iam::6******2:role/aws-ec2-spot-fleet-tagging-role",
					"SpotPrice": "0.15",
					"TargetCapacity": "1",
					"LaunchSpecifications": [{
						"EbsOptimized": "false",
						"InstanceType": {
							"Ref": "myInstanceType"
						},
						"ImageId": ".....",
						"SecurityGroups": [ 
							......
						],
						"SubnetId": {
							"Ref": "mySubnet"
						},
						"WeightedCapacity": "1",
						"UserData": {
							"Fn::Base64": {
								"Fn::Join": [
									"",
									[
....
									]
								]
							}
						}
			

					}]
				}

			},
			"Metadata": {
				"AWS::CloudFormation::Init" : {
				"commands": [
					{
					  "Fn::Join":[
						 "",
						 [
							"echo ls -l /var/log > /home/MyFile.txt \n",
							"chmod 777 /var/log \n"
						 ]
					  ]
				   }
				]
			}
		}
			


Thanks for the helpers!!!!

答案1

得分: 1

元数据块的结构不正确。AWS::CloudFormation::Init 部分应包括一个配置部分,其中提供命令或其他配置详细信息,命令本身应组织为键值对,而不是数组。

以下是您模板中已更正的元数据部分:

"Metadata": {
    "AWS::CloudFormation::Init": {
        "config": {
            "commands": {
                "command1": {
                    "command": {
                        "Fn::Join": [
                            "",
                            [
                                "echo ls -l /var/log > /home/MyFile.txt"
                            ]
                        ]
                    }
                },
                "command2": {
                    "command": "chmod 777 /var/log"
                }
            }
        }
    }
}

用户数据脚本和元数据命令默认在 root 用户下运行。因此,您不需要为 /var/log 提供类似于 '777' 的高级权限。

最后,您的实例需要安装 AWS SSM Agent,以使 AWS::CloudFormation::Init 正常工作。

英文:

The Metadata block has an incorrect structure. The AWS::CloudFormation::Init section should include a config section where you provide commands or other configuration details, and the commands themselves should be organized as key-value pairs, not as an array.

Here's the corrected metadata section of your template:

"Metadata": {
    "AWS::CloudFormation::Init": {
        "config": {
            "commands": {
                "command1": {
                    "command": {
                        "Fn::Join": [
                            "",
                            [
                                "echo ls -l /var/log > /home/MyFile.txt"
                            ]
                        ]
                    }
                },
                "command2": {
                    "command": "chmod 777 /var/log"
                }
            }
        }
    }
}

Userdata scripts and metadata commands run under the root by default. So you don't need to provide high-level permissions like '777' to /var/log.

Finally, your instance needs to have AWS SSM Agent installed for the AWS::CloudFormation::Init to work.

huangapple
  • 本文由 发表于 2023年5月24日 19:34:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定