我需要从RDS获取一些数据,并将其作为cloudwatch指标进行推送。
我在AWS中创建了一个lambda,它与一个可以访问互联网的VPC相关联。但是指标的推送超时了。
为了调试这个,我做了一个dns解析,它工作正常。
有什么想法吗?
代码如下:
print('Loading function')
try:
conn = pymysql.connect(host="kmydb.something.eu-west-1.rds.amazonaws.com", user="myuser", passwd="mypass", db="mydb", connect_timeout=5)
print("SUCCESS: Connection to RDS MySQL instance succeeded")
item_count = 0
with conn.cursor() as cur:
print("Executing SQL command")
cur.execute("select count(*) from something")
for row in cur:
item_count = row[0]
print("DONE: Executing SQL command -> Rows: {}".format(item_count) )
conn.commit()
print("DEBUG: Going to push now.")
hostName = "something.something.com"
ipAddress = socket.gethostbyname(hostName)
print("IP address of the host name {} is: {}".format(hostName, ipAddress))
if pushToCloudwatch(item_count):
print("DEBUG: Pushed sucessfull.")
else:
print("ERROR: Pushed NOT sucessfull.")
except pymysql.MySQLError as e:
print("ERROR: Unexpected error: Could not connect to MySQL instance.")
print("error: {}".format(e))
sys.exit()
def pushToCloudwatch(channels):
print("ERROR: Creating client.")
client = boto3.client('cloudwatch',region_name="us-west-1")
print("ERROR: client created... pushing.")
response = client.put_metric_data(
Namespace='INFRA-VOICE',
MetricData=[
{
'MetricName': 'CurrentP',
'Dimensions': [
{
'Name': 'INFRA',
'Value': 'CurrentP'
},
],
'Value': 0,
'Unit': 'Count'
}
]
)
print("ERROR: Response received.")
print( "Response: {}".format(response) )
return True发布于 2021-03-13 05:50:53
所以重点是,你必须:
<代码>F29
如下所示:

这对我帮助很大:
Amazon AWS NAT Gatway not working, EC2 doesn't register in ECS Cluster
解决了。
https://stackoverflow.com/questions/66592586
复制相似问题