Documentation
¶
Overview ¶
Package aws provides AWS SDK helpers for simulation packs.
Index ¶
- func AWSConfig(ctx context.Context) (aws.Config, error)
- func AssumeAWSRole(ctx context.Context, cfg aws.Config, roleArn string, opts ...AssumeRoleOption) (aws.Config, error)
- func RunSSMCommand(ctx context.Context, ssmClient *ssm.Client, instanceID, command string, ...) (string, error)
- type AssumeRoleOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AWSConfig ¶
AWSConfig creates an AWS SDK v2 config using the default credential chain. The AWS SDK automatically reads from standard environment variables:
- AWS_ACCESS_KEY_ID: AWS access key ID
- AWS_SECRET_ACCESS_KEY: AWS secret access key
- AWS_SESSION_TOKEN: AWS session token (optional)
- AWS_REGION or AWS_DEFAULT_REGION: AWS region
- AWS_PROFILE: AWS profile name
It also supports shared credentials file (~/.aws/credentials) and EC2/ECS instance metadata.
func AssumeAWSRole ¶
func AssumeAWSRole(ctx context.Context, cfg aws.Config, roleArn string, opts ...AssumeRoleOption) (aws.Config, error)
AssumeAWSRole assumes an AWS IAM role with retry logic for eventual consistency. Returns a new config with assumed role credentials. The retry logic handles the delay between role creation and assumability.
func RunSSMCommand ¶
func RunSSMCommand(ctx context.Context, ssmClient *ssm.Client, instanceID, command string, timeout time.Duration) (string, error)
RunSSMCommand executes a shell command on an EC2 instance via SSM and waits for completion. It combines SendCommand and WaitForOutput into a single call. Returns the command output on success.
Example:
output, err := aws.RunSSMCommand(ctx, ssmClient, instanceID, "echo hello", 30*time.Second)
if err != nil {
log.WithError(err).Warn("Command failed")
}
Types ¶
type AssumeRoleOption ¶
type AssumeRoleOption func(*assumeRoleConfig)
AssumeRoleOption configures role assumption behavior.
func WithExternalID ¶
func WithExternalID(externalID string) AssumeRoleOption
WithExternalID sets the external ID for role assumption.
func WithRetryBackoff ¶
func WithRetryBackoff(initial, maxInterval, maxElapsed time.Duration) AssumeRoleOption
WithRetryBackoff configures retry behavior for role assumption. Default: 1s initial, 10s max interval, 1min total time.