简体   繁体   English

使用 python 将文件从 s3 存储桶复制到 ec2 实例

[英]Copy files from s3 bucket to ec2 instance using python

I have a bashscript present in S3 bucket.i need to run that bashscript in my EC2 instance using python.我在 S3 存储桶中有一个 bashscript。我需要使用 python 在我的 EC2 实例中运行该 bashscript。

I tried using ssm but it is not working.我尝试使用 ssm 但它不起作用。

 params={
'sourceType': ['S3'],
'path': ['https://test-bucket.s3.us-west-2.amazonaws.com/testscript.sh'],
'commands' : ['sh testscript.sh'],
}

testCommand = ssm_client.send_command( InstanceIds=[ InstanceId], DocumentName='AWS-RunShellScript', Parameters= params)

Can someone please help me solving this issue有人可以帮我解决这个问题吗

Try by the following method, add the below in your command document通过以下方法尝试,在命令文档中添加以下内容

---
schemaVersion: "2.2"
description: "Command Document Example JSON Template"
parameters:
  Message:
    type: "String"
    description: "Run command through S3"
    default: "Run command through S3"
mainSteps:
- action: "aws:runShellScript"
  name: "s3commandexecution"
  inputs:
    runCommand:
    - curl -L https://test-bucket.s3.us-west-2.amazonaws.com/testscript.sh > testscript.sh
    - ./testscript.sh

Then run your command through python boto3然后通过 python boto3 运行你的命令

testCommand = ssm_client.send_command( InstanceIds=[ InstanceId], DocumentName='AWS-RunShellScript')

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

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