使用BOTO3 SSM上传没有SSH KeyPair的文件到EC2实例
BOTO3的SSM客户端使用AWS配置设置作为身份验证机制,允许Python程序在远程EC2实例上运行命令。
我想将文件上传到EC2实例。上一篇问题(如何使用BOTO3通过SSM代理到EC2实例并发送文件)表示这是可以通过SSH进行的。
是否可以在没有SSH Keypair的情况下使用SSM上传文件?
做到这一点的一种方法可能是:
with open('path/to/file', r) as f:
contents = f.read()
resp = boto3('ssm').send_command(
InstanceIds=[...],
Commands=[f'echo "{contents}" > file.txt']
)
但这似乎很脆弱。
上下文:我正在构建一个本应由非技术用户运行的脚本。该脚本设置了一个新的EC2实例,并在该实例上以编程方式运行多个命令来设置HTTP服务器。据我所知,没有一种很好的方法可以自动生成SSH Keypair,而且我不想在每个部署的EC2实例中手动管理多个SSH Keypairs。
The SSM client for boto3 uses AWS config settings as an authentication mechanism, allowing a python program to run commands on a remote ec2 instance.
I would like to upload files to the ec2 instance. Previous SO questions (How to scp to ec2 instance via ssm agent using boto3 and send file) indicate that this is possible over ssh.
Is it possible to upload files to the instance using SSM without an SSH keypair?
One way to do this may be something like:
with open('path/to/file', r) as f:
contents = f.read()
resp = boto3('ssm').send_command(
InstanceIds=[...],
Commands=[f'echo "{contents}" > file.txt']
)
but this seems very fragile.
Context: I am building a script that is meant to be run by non-technical users. The script sets up a new EC2 instance and programmatically runs several commands on that instance to set up a http server. As far as I know, there is not a good way to automatically generate ssh keypairs, and I dont want to have to manually manage multiple ssh keypairs for every ec2 instance that is deployed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并不是一个答案,但是我最终提出了 @Markb的建议,将S3文件作为中介创建并从那里上传/下载。
Not quite an answer, but I ended up going with @MarkB's suggestion to create an S3 file as an intermediary and upload/download from there.