使用Lambda和psycopg2连接到Redshift时模块初始化错误

时间:2019-07-05 12:45:12

标签: python amazon-web-services aws-lambda amazon-redshift

当我尝试连接redshift集群时遇到错误。

我已经导入了所有用于在lambda上运行python代码的库。 运行Python代码会产生错误。

import json
import boto3
import os
import psycopg2
import base64
from datetime import datetime
import logging
import sys
import hashlib
import urllib
import platform


def lambda_test():
    print('hello')
    conn_string = "dbname='dev' port='5439' user='my-user' password='my-password' host='redshift-cluster-1.calcocahphdx.us-east-1.redshift.amazonaws.com:5439'"
    conn = psycopg2.connect(conn_string)

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

lambda_test()

响应:

{
  "errorMessage": "module initialization error"
}

Request ID:
"e9a8c853-f0d0-486c-8210-5c39fb7f660b"

Function Logs:
START RequestId: e9a8c853-f0d0-486c-8210-5c39fb7f660b Version: $LATEST
module initialization error: could not translate host name "redshift-cluster-1.calcocahphdx.us-east-1.redshift.amazonaws.com:5439" to address: Name or service not known


END RequestId: e9a8c853-f0d0-486c-8210-5c39fb7f660b
REPORT RequestId: e9a8c853-f0d0-486c-8210-5c39fb7f660b  Duration: 510.13 ms Billed Duration: 600 ms     Memory Size: 128 MB Max Memory Used: 61 MB  
module initialization error
could not translate host name "redshift-cluster-1.calcocahphdx.us-east-1.redshift.amazonaws.com:5439" to address: Name or service not known

0 个答案:

没有答案