EndpointConnectionError:无法连接到端点URL:“ http://169.254.169.254 / .....”

时间:2019-05-30 20:34:44

标签: python-2.7 amazon-web-services amazon-iam

我正在尝试使用Python脚本创建AWS RDS并部署lambda函数。但是,我遇到错误,看来它无法与aws命令通信以创建rds。

DEBUG: Caught retryable HTTP exception while making metadata service request to http://169.254.169.254/latest/meta-data/iam/security-credentials/: Could not connect to the endpoint URL: "http://169.254.169.254/latest/meta-data/iam/security-credentials/"

Traceback (most recent call last):

 File "/usr/lib/python2.7/site-packages/botocore/utils.py", line 303, in _get_request
 response = self._session.send(request.prepare())
File "/usr/lib/python2.7/site-packages/botocore/httpsession.py", line 282, in send raise EndpointConnectionError(endpoint_url=request.url, error=e)

EndpointConnectionError: Could not connect to the endpoint URL: "http://169.254.169.254/latest/meta-data/iam/security-credentials/"

我正在通过SSO okta获得aws凭证。在〜/ .aws目录中,下面分别是'credentials'和'config'文件的内容。

[default]
aws_access_key_id = <Key Id>
aws_secret_access_key = <Secret Key>
aws_session_token = <Token>

[default]
region = us-west-2

```python
```
for az in availability_zones:
    if aurora.get_db_instance(db_instance_identifier + "-" + az)[0] != 0:
        aurora.create_db_instance(db_cluster_identifier, db_instance_identifier + "-" + az, az, subnet_group_identifier, db_instance_type)
    else:
        aurora.modify_db_instance(db_cluster_identifier, db_instance_identifier + "-" + az, az, db_instance_type)

# Wait for DB to become available for connection
iter_max = 15
iteration = 0
for az in availability_zones:
    while aurora.get_db_instance(db_instance_identifier + "-" + az)[1]["DBInstances"][0]["DBInstanceStatus"] != "available":
        iteration += 1
        if iteration < iter_max:
            logging.info("Waiting for DB instances to become available - iteration " + str(iteration) + " of " + str(iter_max))
            time.sleep(10*iteration)
        else:
            raise Exception("Waiting for DB Instance to become available timed out!")

cluster_endpoint = aurora.get_db_cluster(db_cluster_identifier)[1]["DBClusters"][0]["Endpoint"]

下面的实际错误来自while循环,DEBUG显示无法找到凭证,但是凭证在那里。我可以使用相同的aws凭证从cli部署Elastic Beanstalk环境,但不能这样做。看起来上面的aurora.create_db_instance命令失败。

DEBUG: Unable to locate credentials

Traceback (most recent call last):

  File "./deploy_api.py", line 753, in <module> sync_rds()
  File "./deploy_api.py", line 57, in sync_rds
    while aurora.get_db_instance(db_instance_identifier + "-" + az)[1]["DBInstances"][0]["DBInstanceStatus"] != "available":

TypeError: 'NoneType' object has no attribute '__getitem__'

1 个答案:

答案 0 :(得分:0)

我遇到此错误是因为ECS任务没有写入DynamoDB的权限。导致问题的代码是:

从boto3导入资源

dynamodb_resource = resource(“ dynamodb”)

当我为resource()函数调用填写region_name,aws_access_key_id和aws_secret_access_key参数时,问题已解决。

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.resource

如果这不能解决您的问题,请检查连接到AWS服务的代码,并确保您填写了所有适当的功能参数。