部分凭据找到明确的,缺失:aws_access_key_id

huangapple go评论74阅读模式
英文:

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(&#39;AWS_ACCESS_KEY&#39;)
AWS_SECRET_KEY=os.getenv(&#39;AWS_SECRET_KEY&#39;)

translate = boto3.client(
    service_name=&#39;translate&#39;,
    region_name=&#39;us-east-1&#39;, 
    aws_access_key_id=AWS_ACCESS_KEY, 
    aws_secret_access_key=AWS_SECRET_KEY, 
)

result = translate.translate_text(Text=&quot;Hello, World&quot;, 
            SourceLanguageCode=&quot;en&quot;, TargetLanguageCode=&quot;de&quot;)
print(&#39;TranslatedText: &#39; + result.get(&#39;TranslatedText&#39;))
print(&#39;SourceLanguageCode: &#39; + result.get(&#39;SourceLanguageCode&#39;))
print(&#39;TargetLanguageCode: &#39; + result.get(&#39;TargetLanguageCode&#39;))

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 &quot;/home/myuser/Desktop/mika/test.py&quot;, line 8, in &lt;module&gt;
    translate = boto3.client(
  File &quot;/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/boto3/__init__.py&quot;, line 92, in client
    return _get_default_session().client(*args, **kwargs)
  File &quot;/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/boto3/session.py&quot;, line 299, in client
    return self._session.create_client(
  File &quot;/home/myuser/Desktop/mika/venv/lib/python3.10/site-packages/botocore/session.py&quot;, 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组织管理员(拥有启用/禁用权限的合适权限)进行的以下更改(与权限相关):

  1. AWS组织管理员已将角色AWSAdministratorAccessAWSPowerUserAccess添加到以下条件中:
"ArnNotLike": {
      "aws:PrincipalARN": [
        "arn:aws:iam::*:role/AWSControlTowerExecution",
        "arn:aws:iam::*:role/AWSAdministratorAccess",
        "arn:aws:iam::*:role/AWSPowerUserAccess"
      ]
    }
  1. 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:

  1. Roles AWSAdministratorAccess & AWSPowerUserAccess where added to the following Condition, by the AWS Organization Administrator:
&quot;ArnNotLike&quot;: {
          &quot;aws:PrincipalARN&quot;: [
            &quot;arn:aws:iam::*:role/AWSControlTowerExecution&quot;,
            &quot;arn:aws:iam::*:role/AWSAdministratorAccess&quot;,
            &quot;arn:aws:iam::*:role/AWSPowerUserAccess&quot;
          ]
        }
  1. translate:* service was added to the policy:
&quot;NotAction&quot;: [
        &quot;translate:*&quot;,
        &quot;a4b:*&quot;,
        ...

With these changes, the Python script now displays the desired output:

TranslatedText: Hallo, Welt
SourceLanguageCode: en
TargetLanguageCode: de

huangapple
  • 本文由 发表于 2023年7月14日 05:25:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定