Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python amazon boto3:run instance with--user data标志对新创建的实例没有影响_Python_Amazon Web Services_Amazon Ec2_Boto3_Aws Cli - Fatal编程技术网

Python amazon boto3:run instance with--user data标志对新创建的实例没有影响

Python amazon boto3:run instance with--user data标志对新创建的实例没有影响,python,amazon-web-services,amazon-ec2,boto3,aws-cli,Python,Amazon Web Services,Amazon Ec2,Boto3,Aws Cli,我面临的一个问题是,使用boto3api提供用户数据标志没有任何效果,而awscli工作得非常好 用户数据文件保存原始bash命令(无base64encode) 工作样本: aws ec2 run-instances --user-data "file://C:\Users\koko\PycharmProjects\AWS\test.txt" --image-id ami-9abea4fb --count 1 --instance-type t2.micro --key-name KEY --s

我面临的一个问题是,使用
boto3
api提供用户数据标志没有任何效果,而
awscli
工作得非常好

用户数据文件保存原始bash命令(无base64encode)

工作样本:

aws ec2 run-instances --user-data "file://C:\Users\koko\PycharmProjects\AWS\test.txt" --image-id ami-9abea4fb --count 1 --instance-type t2.micro --key-name KEY --security-group-ids "SomeKey" --region us-west-2
这是不工作的boto3样本:

 res = client.run_instances(
            ImageId=imageId,
            InstanceType=instanceType,
            MinCount=count,
            MaxCount=count,
            SecurityGroupIds=securityGroupId.split(),
            UserData='file://C:\\Users\\koko\\PycharmProjects\\AWS\\userdata.cfg',
            KeyName=keyName)
根据实际创建的返回json+实例,这两个命令都成功执行

此外,我还尝试比较amazon GUI中的用户数据字段,它们都是相同的


编辑:当我查看boto3生成的所有实例的用户数据内容时,我看到了提供给脚本的文件路径,与aws cli相反,aws cli扩展了实际脚本。用户数据参数是一个字符串,其内容成为用户数据

虽然允许您将文件指定为输入,但boto3不允许


你的应用程序将需要读取文件的内容,然后将内容作为字符串传递给
run_instances()
函数。

用户数据参数是一个字符串,其内容将成为用户数据

虽然允许您将文件指定为输入,但boto3不允许

您的应用程序需要读取文件的内容,然后将内容作为字符串传递给
run_instances()
函数