package aws

import (
	"context"
	"fmt"

	"github.com/aws/aws-sdk-go-v2/service/ssm"
)

// GetAMIID returns the AMI ID of the given parameter name.
// If the parameter is not found, it will return an error.
func GetAMIID(ctx context.Context, cli *ssm.Client, name string) (value *string, err error) {
	params, err := cli.GetParameter(ctx, &ssm.GetParameterInput{
		Name: &name,
	})
	if err != nil {
		return nil, err
	}

	if params.Parameter != nil {
		return params.Parameter.Value, nil
	}

	return nil, fmt.Errorf("the parameter in the output is nil")
}
