boto3例外nocredentialserror

发布于 2025-01-24 03:46:49 字数 2089 浏览 1 评论 0原文

我正在尝试通过此教程 https://docs.aws.aws.amazon.com/amazons3/latest/userguide/tutorial-s3-object-lambda-uppercase.html#ol-upper-step6

一切作品除了步骤7中的代码外,也就是说:

 import boto3

 s3 = boto3.client('s3')
 print("printing boto version: " + boto3.__version__)


def getObject(bucket, key):
   objectBody = s3.get_object(Bucket = bucket, Key = key)
   print(objectBody["Body"].read().decode("utf-8"))
   print("\n")

 print('Original object from the S3 bucket:')
 
# Replace the two input parameters of getObject() below with
# the S3 bucket name that you created in Step 1 and
# the name of the file that you uploaded to the S3 bucket in Step 2
 getObject(<<My Bucket name>>,
      "tutorial.txt")

 print('Object transformed by S3 Object Lambda:')
# Replace the two input parameters of getObject() below with
# the ARN of your S3 Object Lambda access point that you saved earlier and
# the name of the file with the transformed data (which in this case is
# the same as the name of the file that you uploaded to the S3 bucket
# in Step 2)
 getObject(<<MY_ARN>>,
      "tutorial.txt")

我正确复制了Arn和Bucket名称,但是我仍然例外:

        File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/hooks.py", line 212, in _emit
        response = handler(**kwargs)
       File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/signers.py", line 95, in handler
       return self.sign(operation_name, request)
       File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/signers.py", line 167, in sign
         auth.add_auth(request)
     File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/auth.py", line 401, in add_auth
      raise NoCredentialsError()
     botocore.exceptions.NoCredentialsError: Unable to locate credentials

我缺少什么?

I am trying to test sample AWS lamda code through this tutorial https://docs.aws.amazon.com/AmazonS3/latest/userguide/tutorial-s3-object-lambda-uppercase.html#ol-upper-step6

Everything works except the code in Step 7, that is:

 import boto3

 s3 = boto3.client('s3')
 print("printing boto version: " + boto3.__version__)


def getObject(bucket, key):
   objectBody = s3.get_object(Bucket = bucket, Key = key)
   print(objectBody["Body"].read().decode("utf-8"))
   print("\n")

 print('Original object from the S3 bucket:')
 
# Replace the two input parameters of getObject() below with
# the S3 bucket name that you created in Step 1 and
# the name of the file that you uploaded to the S3 bucket in Step 2
 getObject(<<My Bucket name>>,
      "tutorial.txt")

 print('Object transformed by S3 Object Lambda:')
# Replace the two input parameters of getObject() below with
# the ARN of your S3 Object Lambda access point that you saved earlier and
# the name of the file with the transformed data (which in this case is
# the same as the name of the file that you uploaded to the S3 bucket
# in Step 2)
 getObject(<<MY_ARN>>,
      "tutorial.txt")

I have correctly copied ARN and bucket name, but still I get exception:

        File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/hooks.py", line 212, in _emit
        response = handler(**kwargs)
       File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/signers.py", line 95, in handler
       return self.sign(operation_name, request)
       File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/signers.py", line 167, in sign
         auth.add_auth(request)
     File "/Users/deepaksharma/object-lamba/env/lib/python3.8/site-packages/botocore/auth.py", line 401, in add_auth
      raise NoCredentialsError()
     botocore.exceptions.NoCredentialsError: Unable to locate credentials

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两仪 2025-01-31 03:46:49

您需要与AWS帐户建立会话。

在Python中建立会话:

import boto3

session = boto3.Session( 
         aws_access_key_id='<your_access_key_id>', 
         aws_secret_access_key='<your_secret_access_key>')

s3 = session.client('s3')

或者,配置您的CLI:

aws configure
<enter key>
<enter secret>
<enter region>
<enter output format>

You need to establish a session with your AWS account.

Establish a session in Python:

import boto3

session = boto3.Session( 
         aws_access_key_id='<your_access_key_id>', 
         aws_secret_access_key='<your_secret_access_key>')

s3 = session.client('s3')

Or, configure your CLI:

aws configure
<enter key>
<enter secret>
<enter region>
<enter output format>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文