add manual credentials

This commit is contained in:
schulze 2023-03-20 15:43:14 +01:00
parent 4103f10502
commit e31a66a59d
4 changed files with 6 additions and 5 deletions

View File

@ -3,4 +3,4 @@ aws:
- us-east-1
- us-east-2
- us-west-1
credentials_path: ./mtd_aws/.credentials

View File

@ -27,7 +27,7 @@ func main() {
for _, region := range config.AWS.Regions {
fmt.Println("Listing instances in region:", region)
aws_config := mtd_aws.New_config(region)
aws_config := mtd_aws.New_config(region, config.AWS.Credentials_path)
instances, err := mtd_aws.Instances(aws_config)
if err != nil {
fmt.Println("Error listing instances:", err)

View File

@ -10,9 +10,9 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
)
func New_config(region string) aws.Config {
func New_config(region string, credentials string) aws.Config {
// Create a new AWS config
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithSharedConfigFiles([]string{credentials}), config.WithRegion(region))
if err != nil {
fmt.Println("Error creating config:", err)
fmt.Println("Configure Credentials in line with the documentation found here: https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#specifying-credentials")

View File

@ -9,7 +9,8 @@ import (
type Config struct {
AWS struct {
Regions []string `yaml:"regions"`
Regions []string `yaml:"regions"`
Credentials_path string `yaml:"credentials_path"`
} `yaml:"aws"`
}