1

i am trying to automate file update on s3 using aws cli. when i manually run the code aws s3 cp /home/abc/lampdata.json s3://lamp it is working completely fine but in shell script file it is giving me an error

#!/bin/sh exec bash -c 'AWS_CONFIG_FILE=/root/.aws/config aws s3 cp /home/abc/lampdata.json s3://lamp' &

upload failed: ../../abc/lampdata.json to s3://lamp/lampdata.json Unable to locate credentials

though i have configured using aws configure. is this some problem with the shell script?

4
  • Why do you need the AWS_CONFIG_FILE environment variable? seems like that is causing the problems. Commented Sep 7, 2020 at 12:08
  • @TamásSallai thanks for the reply. it is not working with exec aws s3 cp /home/abc/lampdata.json s3://lamp' & either Commented Sep 8, 2020 at 1:23
  • Why do you need exec or bash -c? I believe you can just write bash in a shell script. My other hunch is that maybe you are running the script as a different user? Commented Sep 8, 2020 at 11:01
  • @TamásSallai i was following this. i am using exec inside a .sh file to execute shell script at startup boot on systemd Linux. i confirmed that i am not running the script as a different user. Commented Sep 9, 2020 at 0:46

2 Answers 2

1

@ Siddharth If the credentials already there in ~/.aws/credentials and you are able to execute aws s3 cp from terminal, so no need to specify the credentials in the script. If you set it for User profile and executing the script from that user, then it should inherit your environment by default.

#!/bin/sh
aws s3 cp /home/abc/lampdata.json s3://lamp

This should work.

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

Comments

0

From this source:

import boto3
session = boto3.Session(
    aws_access_key_id=settings.AWS_SERVER_PUBLIC_KEY,
    aws_secret_access_key=settings.AWS_SERVER_SECRET_KEY,
)
Then use that session to get an S3 resource:

s3 = session.resource('s3')

Comments

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.