英文:
Partial credentials found in explicit, missing: aws_access_key_id
问题
我正在尝试运行以下代码片段(基于此处的代码1):
import boto3, os
from dotenv import load_dotenv
load_dotenv()
AWS_ACCESS_KEY=os.getenv('AWS_ACCESS_KEY')
AWS_SECRET_KEY=os.getenv('AWS_SECRET_KEY')
translate = boto3.client(
service_name='translate',
region_name='us-east-1',
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY,
)
result = translate.translate_text(Text="Hello, World",
SourceLanguageCode="en", TargetLanguageCode="de")
print('TranslatedText: ' + result.get('TranslatedText'))
print('SourceLanguageCode: ' + result.get('SourceLanguageCode'))
print('TargetLanguageCode: ' + result.get('TargetLanguageCode'))
我的.env
文件如下(出于安全原因已编辑):
AWS_ACCESS_KEY=AXXXXXXXXXXXXXXXXXXR
AWS_ACCESS_KEY=+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXa
我收到的错误是:
Traceback (most recent call last):
File "/home/myuser/Desktop/mika/test.py", line 8, in <module>
translate = boto3.client(
File "/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/boto3/__init__.py", line 92, in client
return _get_default_session().client(*args, **kwargs)
File "/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/boto3/session.py", line 299, in client
return self._session.create_client(
File "/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/botocore/session.py", line 950, in create_client
raise PartialCredentialsError(
botocore.exceptions.PartialCredentialsError: Partial credentials found in explicit, missing: aws_access_key_id
我已经检查了多种情况,类似于“Partial credentials found in env
”,但它们似乎不符合当前情况。
我做错了什么?
英文:
I am trying to run the following code snipet (based on this code here):
import boto3, os
from dotenv import load_dotenv
load_dotenv()
AWS_ACCESS_KEY=os.getenv('AWS_ACCESS_KEY')
AWS_SECRET_KEY=os.getenv('AWS_SECRET_KEY')
translate = boto3.client(
service_name='translate',
region_name='us-east-1',
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY,
)
result = translate.translate_text(Text="Hello, World",
SourceLanguageCode="en", TargetLanguageCode="de")
print('TranslatedText: ' + result.get('TranslatedText'))
print('SourceLanguageCode: ' + result.get('SourceLanguageCode'))
print('TargetLanguageCode: ' + result.get('TargetLanguageCode'))
My .env
file is the following (edited for security reasons):
AWS_ACCESS_KEY=AXXXXXXXXXXXXXXXXXXR
AWS_ACCESS_KEY=+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXa
The error I am getting is:
Traceback (most recent call last):
File "/home/myuser/Desktop/mika/test.py", line 8, in <module>
translate = boto3.client(
File "/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/boto3/__init__.py", line 92, in client
return _get_default_session().client(*args, **kwargs)
File "/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/boto3/session.py", line 299, in client
return self._session.create_client(
File "/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/botocore/session.py", line 950, in create_client
raise PartialCredentialsError(
botocore.exceptions.PartialCredentialsError: Partial credentials found in explicit, missing: aws_access_key_id
I have checked the several cases here that go like "Partial credentials found in env
", but they do not seem as a match of the current case.
What am I doing wrong?
答案1
得分: 0
在你的.env
文件中有SERVER_PUBLIC_KEY
,但在Python代码中有AWS_SERVER_PUBLIC_KEY
。
英文:
In your .env
you have SERVER_PUBLIC_KEY
, but in the python code there is AWS_SERVER_PUBLIC_KEY
.
答案2
得分: 0
经过与AWS支持团队的内部修订,以及我公司的AWS组织管理员(拥有启用/禁用权限的合适权限)进行的以下更改(与权限相关):
- AWS组织管理员已将角色
AWSAdministratorAccess
和AWSPowerUserAccess
添加到以下条件中:
"ArnNotLike": {
"aws:PrincipalARN": [
"arn:aws:iam::*:role/AWSControlTowerExecution",
"arn:aws:iam::*:role/AWSAdministratorAccess",
"arn:aws:iam::*:role/AWSPowerUserAccess"
]
}
translate:*
服务已添加到策略中:
"NotAction": [
"translate:*",
"a4b:*",
...
通过这些更改,Python脚本现在显示所期望的输出:
TranslatedText: Hallo, Welt
SourceLanguageCode: en
TargetLanguageCode: de
英文:
After an internal revision with AWS Support Team, and the AWS Organization Administrator of my company (who has the proper rights to enable / disable permissions), the following changes (linked to permissions) where done:
- Roles
AWSAdministratorAccess
&AWSPowerUserAccess
where added to the following Condition, by the AWS Organization Administrator:
"ArnNotLike": {
"aws:PrincipalARN": [
"arn:aws:iam::*:role/AWSControlTowerExecution",
"arn:aws:iam::*:role/AWSAdministratorAccess",
"arn:aws:iam::*:role/AWSPowerUserAccess"
]
}
translate:*
service was added to the policy:
"NotAction": [
"translate:*",
"a4b:*",
...
With these changes, the Python script now displays the desired output:
TranslatedText: Hallo, Welt
SourceLanguageCode: en
TargetLanguageCode: de
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论