我嘗試在 ECS 中午餐應用程序。在我本地的docker環境中吃午飯是沒有問題的。但是由于rds連接問題,無法訪問ECS中的api服務器。我在 api 服務器中使用 golang,在 db 中使用 mysql。我在 main.go 中調用db.gofunc main() { db := db.NewDatabase(os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"))連接rds數據庫時出現錯誤func NewDatabase(user, password, host string) *Database { db, err := sql.Open("mysql", user+":"+password+"@tcp("+host+":3306)/article") if err != nil { panic(err.Error()) } err = db.Ping() // error occurs here if err != nil { panic(err.Error()) }我將它部署到彈性豆莖上。我檢查了環境變量是否設置正確。這是完整的源代碼: https://github.com/jpskgc/article我預計彈豆不會有錯誤。但實際情況并非如此。我想知道解決方案。這是elastic beanstalk中的錯誤日志。-------------------------------------/var/log/containers/server-4c66c8d1848a-stdouterr.log-------------------------------------panic: dial tcp 172.31.26.91:3306: connect: connection timed outgoroutine 1 [running]:article/api/db.NewDatabase(0xc00002401b, 0x4, 0xc00002a00f, 0xb, 0xc00002800b, 0x3c, 0xdb94f2) /app/db/db.go:20 +0x3bcmain.main() /app/main.go:18 +0xee
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消