func fetchConfigFromParameterStore()

in PetAdoptions/cdk/pet_stack/resources/microservices/petlistadoptions-go/config.go [47:75]


func fetchConfigFromParameterStore(region string) (Config, error) {
	svc := ssm.New(session.New(&aws.Config{Region: aws.String(region)}))
	xray.AWS(svc.Client)
	ctx, seg := xray.BeginSegment(context.Background(), "petlistadoptions")
	defer seg.Close(nil)

	res, err := svc.GetParametersWithContext(ctx, &ssm.GetParametersInput{
		Names: []*string{
			aws.String("/petstore/rdssecretarn"),
			aws.String("/petstore/searchapiurl"),
		},
	})

	cfg := Config{}

	if err != nil {
		return cfg, err
	}

	for _, p := range res.Parameters {
		if aws.StringValue(p.Name) == "/petstore/rdssecretarn" {
			cfg.RDSSecretArn = aws.StringValue(p.Value)
		} else if aws.StringValue(p.Name) == "/petstore/searchapiurl" {
			cfg.PetSearchURL = aws.StringValue(p.Value)
		}
	}

	return cfg, err
}