简体   繁体   English

带有 boto3 的 Python3 语法

[英]Python3 Syntax with boto3

So i am creating a script using python and boto3 to start a aws machine with the settings i want and for it to create a apache webserver, part of the project is to edit the default apache webpage.所以我正在使用 python 和 boto3 创建一个脚本来启动一台具有我想要的设置的 aws 机器并让它创建一个 apache 网络服务器,项目的一部分是编辑默认的 ZB6EFD606D118D0F62066E3141900 网页。

So i have everything set up and running, and currently editing the webpage to include a picture from an s3 aws bucket.所以我已经设置并运行了所有东西,目前正在编辑网页以包含来自 s3 aws 存储桶的图片。 One problem i am having is that i cant get the syntax quite right to automatically ssh in and put the HTML code into index.html.我遇到的一个问题是我无法完全正确地自动输入 ssh 并将 HTML 代码放入 index.html 中。 The code i have is correct but i cant figure out the syntax as it uses many quotes.我拥有的代码是正确的,但我无法弄清楚语法,因为它使用了很多引号。

Heres a variable for the string.这是字符串的变量。 It is mainly the sudo echo part im struggling with, not the ssh, as the SSH works.它主要是我在苦苦挣扎的 sudo echo 部分,而不是 ssh,因为 SSH 有效。

cmd5 = "ssh -o StrictHostKeyChecking=no -i assignment1.pem ec2-user@" + publicIP + " sudo echo '<image src = \"https://dylanbucket250199141112.s3-eu-west-1.amazonaws.com/image.jpg\"> </image>' >> /var/www/html/index.html"

Heres the subprocess im using.这是我正在使用的子流程。

subprocess.run(cmd5, shell = True)

If you want to forgo the quotation issue, you can use this format for modifying the file:如果你想放弃报价问题,你可以使用这种格式来修改文件:

echo '<image src = "https://dylanbucket250199141112.s3-eu-west-1.amazonaws.com/image.jpg"> </image>' | ssh ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM