<p>I am using the following job template:</p>

<pre><code> apiVersion: batch/v1
kind: Job
metadata:
  name: rotatedevcreds2
spec:
  template:
    metadata:
      name: rotatedevcreds2
    spec:
      containers:
      - name: shell
        image: akanksha/dsserver:v7
      env:
      - name: DEMO
        value: "Hello from the environment"
      - name: personal_AWS_SECRET_ACCESS_KEY
        valueFrom:
          secretKeyRef:
            name: rotatecreds-env
            key: personal_aws_secret_access_key
      - name: personal_AWS_SECRET_ACCESS_KEY_ID
        valueFrom:
          secretKeyRef:
            name: rotatecreds-env
            key: personal_aws_secret_access_key_id
      - name: personal_GIT_TOKEN
        valueFrom:
          secretKeyRef:
            name: rotatecreds-env
            key: personal_git_token
        command:
         - "bin/bash"
         - "-c"
         - "whoami; pwd; /root/rotateCreds.sh"
      restartPolicy: Never
      imagePullSecrets:
      - name: regcred
</code></pre>

<p>The shell script runs some ansible tasks which results in:</p>

<pre><code>    TASK [Get the existing access keys for the functional backup ID] ***************
    fatal: [localhost]: FAILED! =&gt; {"changed": false, "cmd": "aws iam list-access-keys --user-name ''", "failed_when_result": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
</code></pre>

<p>However if I spin a pod using the same iamge using the following </p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: rotatedevcreds3
spec:
  template:
    metadata:
      name: rotatedevcreds3
    spec:
      containers:
      - name: shell
        image: akanksha/dsserver:v7
        env:
        - name: DEMO
          value: "Hello from the environment"
        - name: personal_AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: rotatecreds-env
              key: personal_aws_secret_access_key
        - name: personal_AWS_SECRET_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: rotatecreds-env
              key: personal_aws_secret_access_key_id
        - name: personal_GIT_TOKEN
          valueFrom:
            secretKeyRef:
              name: rotatecreds-env
              key: personal_git_token
        command:
         - "bin/bash"
         - "-c"
         - "whoami; pwd; /root/rotateCreds.sh"
      restartPolicy: Never
      imagePullSecrets:
      - name: regcred
</code></pre>

<p>This creates a POD and I am able to login to the pod and run <code>/root/rotateCreds.sh</code></p>

<p>While running the job it seems it not able to recognose the aws cli. I tried debugging <code>whoami</code> and <code>pwd</code> which is equal to <code>root</code> and <code>/</code> respectively and that is fine. Any pointers what is missing? I am new to jobs.</p>

<p>For further debugging in the job template I added a sleep for <code>10000</code> seconds so that I can login to the container and see what's happening. I noticed after logging in I was able to  run the script manually too. <code>aws</code> command was recognised properly.</p>

codec
<p>It is likely your <code>PATH</code> is not set correctly, 
a quick fix is to define the absolute path of aws-cli like <code>/usr/local/bin/aws</code> in <code>/root/rotateCreds.sh</code> script</p>
