![](/img/trans.png)
[英]How can I run a more powerful AWS EC2 instance that starts and stops when I receive a request?
[英]Getting a aws credentials error when I run user data of ec2 instance
我的 ec2 實例中有一個 shell 腳本,其中包含以下命令
#!/bin/bash
sleep 30
aws s3 sync s3://fbt-pano-input /home/ubuntu/pano/Zip
python3 pano.py
當我直接從實例運行這個 shell 腳本時,它會正確執行。 但是我的實例用戶數據應該運行這個 shell 腳本。 當它嘗試運行它時,它會給出以下錯誤致命錯誤:無法找到憑據
似乎無法運行同步命令從存儲桶下載項目。 我需要提供特殊訪問權限嗎? 幾個小時前它似乎工作正常。 現在突然之間它找不到憑據。
這是我的用戶數據代碼
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/sh
cd /home/ubuntu
sh ./panorama.sh
我的 aws 配置具有正確的憑據。 為什么它給出錯誤
您不應該在您的實例中硬編碼 AWS 憑證。 您的 EC2 應用程序所需的 AWS 權限應通過實例角色提供:
盡管如此,您的用戶數據在root下執行,因此您的應用程序將在根主文件夾中查找憑據,而不是常規 ubuntu 用戶。 要在不同的用戶下運行命令,您可以嘗試以下操作:
runuser - ubuntu -c './panorama.sh'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.