0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IAMロールとEC2でcronからAWS CLIを実行

Posted at

IAMロールをアタッチしたEC2で、cronからシェルスクリプト実行でハマった話。

環境

  • RHEL7.7
  • aws cli/1.18.8
  • IAMロール(S3アップロード権限有)

やりたいこと

cronからS3アップロード処理を記載したシェルスクリプトを実行し、EC2にあるデータをS3にアップロードしたい。

エラー内容

EC2にSSHでログインし手動でシェルスクリプトを実行可能だが
cronから実行すると「aws コマンドが見つかりません」でエラーとなる。

解決方法

  • whichコマンドでAWS CLIのフルパスを確認し、コマンドはフルパスで記載する。
  • シェルスクリプトの冒頭の呼び出しシェルに「-l」オプションを追加
sample.sh
# !/bin/bash -l

/usr/local/bin/aws s3 cp ローカルファイルパス S3バケット

参考記事

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?