英文:
Reading AWS environment variables using python
问题
我已在我的笔记本电脑上配置了AWS CLI。 我正在通过提示或作为代码的一部分传递区域详细信息等。 我能够通过Python连接到AWS并读取项目。
但是,在尝试开发一个类以获取环境变量(如AWS_REGION、AWS_SECRET_ACCESS_KEY等)时,返回的只是null。 除了在我的笔记本电脑上配置AWS CLI之外,我是否漏掉了什么东西。 请注意,在我的(Windows)笔记本电脑上安装时,在提示中输入了AWS_ACCESS_KEY、AWS_SECRET_ACCESS_KEY等。
谢谢
英文:
I've configured AWS CLI in my laptop. I'm passing the region details etc either at prompt or baked as part of the code. I'm able to connect to aws through python and read the items.
But when trying to develop a class so that it get the environment variables like AWS_REGION, AWS_SECRET_ACCESS_KEY etc all that is returned is null. Is there anything i'm missing apart from configuring the aws cli in my laptop. Take note while installing it in my (windows) laptop, at the prompt i enter the AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY etc.
Thanks
答案1
得分: 2
当你第一次下载AWS CLI时,听起来你通过运行aws configure
来配置它,它会要求你提供凭据信息。AWS CLI配置
因此,当你运行AWS命令(CLI或Boto3)时,它会首先查找此配置文件%AWS_CONFIG_FILE%
以获取凭据信息。通过读取这个配置文件,它知道你的默认区域是什么。
你具体想要构建什么?如果是为了读取环境变量,这听起来像是一个Lambda函数,它应该已经设置了AWS_REGION
等环境变量。如果你仍然在本地测试,你将不得不在测试之前自己设置这些环境变量。
英文:
So when you downloaded the AWS CLI the first time it sounds like you went through aws configure
which asked for your credentials. AWS CLI config
So when you run AWS commands (CLI or Boto3) one of the first places it will look for credentials is this config file %AWS_CONFIG_FILE%
. So it knows what your default region is by reading this config file.
What are you exactly trying to build? For reading environment variables, this sounds like a LAMBDA function which would have the environment variables set for AWS_REGION
etc. If still testing on your local machine, you will have to set those yourself prior to testing in the environment variables.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论