1
1
package rds
2
2
3
3
import (
4
+ "errors"
5
+
6
+ "github.com/debeando/go-common/env"
4
7
"github.com/debeando/go-common/retry"
5
8
6
9
"github.com/aws/aws-sdk-go/aws"
@@ -9,28 +12,35 @@ import (
9
12
)
10
13
11
14
type RDS struct {
12
- Client * rds.RDS `json:"-"` // AWS RDS connection.
13
- Instance string `json:"instance"` // New instance (replica).
14
- Class string `json:"class"` // New instance class.
15
- Region string `json:"region"` // AWS region account.
16
- Primary string `json:"primary"` // Source instance (primary).
17
- Status string `json:"status"` // New instance status.
18
- Endpoint string `json:"endpoint"` // New instance endpoint.
19
- Protection bool `json:"protection"` // New instance is set to deletion protection.
20
- Port uint16 `json:"port"` // New instance port of endpoint.
21
- Zone string `json:"zone"` // New instance Availability Zone.
15
+ Client * rds.RDS `json:"-" yaml:"-"` // AWS RDS connection.
16
+ Instance string `json:"instance" yaml:"instance"` // New instance (replica).
17
+ Class string `json:"class" yaml:"class"` // New instance class.
18
+ Region string `json:"region" yaml:"region"` // AWS region account.
19
+ Primary string `json:"primary" yaml:"primary"` // Source instance (primary).
20
+ Status string `json:"status" yaml:"status"` // New instance status.
21
+ Endpoint string `json:"endpoint" yaml:"endpoint"` // New instance endpoint.
22
+ Protection bool `json:"protection" yaml:"protection"` // New instance is set to deletion protection.
23
+ Port uint16 `json:"port" yaml:"port"` // New instance port of endpoint.
24
+ Zone string `json:"zone" yaml:"zone"` // New instance Availability Zone.
25
+ Session * session.Session
22
26
}
23
27
24
28
func (r * RDS ) Init () (err error ) {
25
- sess , err := session . NewSession ( & aws. Config {
26
- Region : aws . String ( r . Region ),
27
- })
29
+ if ! env . Exist ( "AWS_REGION" ) {
30
+ return errors . New ( "You must specify a region. Define value of environment variable AWS_REGION." )
31
+ }
28
32
29
- r .Client = rds .New (sess )
33
+ r .Session = session .Must (session .NewSession ())
34
+
35
+ r .Client = rds .New (r .Session )
30
36
31
37
return
32
38
}
33
39
40
+ func (r * RDS ) GetSessionRegion () string {
41
+ return aws .StringValue (r .Session .Config .Region )
42
+ }
43
+
34
44
func (r * RDS ) List () Instances {
35
45
instances := Instances {}
36
46
instance := Instance {}
0 commit comments