5

I have a awscli command to upload content to s3 bucket. I need to run this command on a ruby script. The command works when executed in terminal. I tried using several methods like backticks and Kernel#system.

value = `aws s3 cp #{published_files} s3://example_bucket/#{meeting_id} --recursive --region us-west-2`

But none of them seem to execute the task. Can anyone suggest any way? It would be of great help

4
  • Have you tried AWS Ruby client docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html ? Could you please specify what do you have stderr/stdout while executing from the Ruby script? Do you execute the script in the same environment where you run the awscli command? Commented Jun 27, 2019 at 14:40
  • @Yann This script is run as a result of finishing an online classroom where the script would receive the path to the recording of the classroom. I need to upload the recording to the bucket. I executed the command in the same server. Commented Jun 27, 2019 at 16:26
  • 1
    @Yann I do not need the response. I just need this cli command to run. Commented Jun 27, 2019 at 16:29
  • The response may content the actual error that happens while trying to execute the command. Kernel#system should work. Try these debug steps: execute the command in irb, try simple aws commands without parameters like aws s3api list-buckets, print the aws command with inserted parameters and verify they are correct. Commented Jun 27, 2019 at 18:43

1 Answer 1

1

Use the sdk instead as it has native support for using s3 https://github.com/aws/aws-sdk-ruby

The API docs are listed here https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3.html

Sign up to request clarification or add additional context in comments.

4 Comments

I need to upload a folder which is quite hard to achieve through the sdk. This cli command should work if I'm able to execute it from the ruby script.
then have the ruby script call a bash script with your command in the script
any idea on how to call a bash script from ruby script?
rubyguides.com/2018/12/ruby-system system(bash /path/to/your/script)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.