botocore.exceptions.NoCredentialsError: Unable to locate credentials - Github Actions
botocore.exceptions.NoCredentialsError: Unable to locate credentials - Github Actions
我正在尝试 运行 AWS SDK python 脚本使用 Github 操作。 Github 操作正在成功安装 Boto3 但脚本正在执行但出现以下错误:
错误:
Run python3 s3.py
Traceback (most recent call last):
File "s3.py", line 5, in <module>
response = s3.list_buckets()
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/botocore/client.py",
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/botocore/signers.py", line 162, in sign
auth.add_auth(request)
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/botocore/auth.py", line 357, in add_auth
raise NoCredentialsError
botocore.exceptions.NoCredentialsError: Unable to locate credentials
Error: Process completed with exit code 1.
目前已实施:
ListS3bucket.yml
name: Python package
on: [push]
jobs:
deploy:
name: sample code
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner.
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Upgrade PIP
run: |
/opt/hostedtoolcache/Python/3.8.6/x64/bin/python -m pip install --upgrade pip
- name: install boto3
run: |
python -m pip install boto3
- name: execute script
env:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
run: |
python3 s3.py
s3.py
import boto3
# Retrieve the list of existing buckets
s3 = boto3.client('s3')
response = s3.list_buckets()
# Output the bucket names
print('Existing buckets:')
for bucket in response['Buckets']:
print(f' {bucket["Name"]}')
请指导。
根据评论。
解决方法是环境变量设置不正确。正确的是 AWS_ACCESS_KEY_ID
、AWS_SECRET_ACCESS_KEY
、AWS_DEFAULT_REGION
,如 docs.
所示
我正在尝试 运行 AWS SDK python 脚本使用 Github 操作。 Github 操作正在成功安装 Boto3 但脚本正在执行但出现以下错误:
错误:
Run python3 s3.py
Traceback (most recent call last):
File "s3.py", line 5, in <module>
response = s3.list_buckets()
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/botocore/client.py",
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/botocore/signers.py", line 162, in sign
auth.add_auth(request)
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/botocore/auth.py", line 357, in add_auth
raise NoCredentialsError
botocore.exceptions.NoCredentialsError: Unable to locate credentials
Error: Process completed with exit code 1.
目前已实施:
ListS3bucket.yml
name: Python package
on: [push]
jobs:
deploy:
name: sample code
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner.
- name: setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Upgrade PIP
run: |
/opt/hostedtoolcache/Python/3.8.6/x64/bin/python -m pip install --upgrade pip
- name: install boto3
run: |
python -m pip install boto3
- name: execute script
env:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
run: |
python3 s3.py
s3.py
import boto3
# Retrieve the list of existing buckets
s3 = boto3.client('s3')
response = s3.list_buckets()
# Output the bucket names
print('Existing buckets:')
for bucket in response['Buckets']:
print(f' {bucket["Name"]}')
请指导。
根据评论。
解决方法是环境变量设置不正确。正确的是 AWS_ACCESS_KEY_ID
、AWS_SECRET_ACCESS_KEY
、AWS_DEFAULT_REGION
,如 docs.