aws

package
v0.0.0-...-61a2cff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

README

Config AK SK and region

Example config:

export AWS_ACCESS_KEY_ID=AKI**************TMN
export AWS_SECRET_ACCESS_KEY=3gQH*******************************AaS9+
export AWS_DEFAULT_REGION=cn-north-1

FAQ

An error occurred (AuthFailure) when calling the CreateSecurityGroup operation: AWS was not able to validate the provided access credentials

this caused by you don't have access to the region, I change the default region to cn-north-1 it works.

Using kubectl to apply infra

apiVersion: infra.sealos.io/v1
kind: Infra
metadata:
  name: aws-infra-demo
spec:
  hosts:
    - roles: [ master ]
      count: 1
      flavor: t2.medium
      image: "ami-0d66b970b9f16f1f5"
      disks:
        - capacity: 23
          volumeType: standard
          type: "root"
        - capacity: 21
          volumeType: gp3
          type: "data"
    - roles: [ node ]
      count: 1
      flavor: t2.medium
      image: "ami-0d66b970b9f16f1f5"
      disks:
        - capacity: 11
          volumeType: gp3
          type: "root"
        - capacity: 13
          volumeType: gp3
          type: "data"

kubectl apply -f infra.yaml

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImages

GetImages retrieves information about your Amazon Elastic Compute Cloud (Amazon EC2) images. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a DescribeImagesOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to DescribeImages.

func GetInstanceStatus

GetInstanceStatus retrieves information about your Amazon Elastic Compute Cloud (Amazon EC2) instances. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a DescribeInstancesOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to DescribeInstances.

func GetInstanceType

func GetInstanceType(hosts *v1.Hosts) types.InstanceType

func GetInstances

GetInstances retrieves information about your Amazon Elastic Compute Cloud (Amazon EC2) instances. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a DescribeInstancesOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to DescribeInstances.

func GetVolumes

GetVolumes retrieves volumes information about your Amazon Elastic Compute Cloud (Amazon EC2) instances. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a DescribeInstancesOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to DescribeInstances.

func MakeInstance

MakeInstance creates an Amazon Elastic Compute Cloud (Amazon EC2) instance. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a RunInstancesOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to RunInstances.

func MakeTags

MakeTags creates tags for an Amazon Elastic Compute Cloud (Amazon EC2) instance. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a CreateTagsOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to CreateTags.

func StopInstance

StopInstance stops an Amazon Elastic Compute Cloud (Amazon EC2) instance. Inputs:

c is the context of the method call, which includes the AWS Region.
api is the interface that defines the method call.
input defines the input arguments to the service call.

Output:

If success, a StopInstancesOutput object containing the result of the service call and nil.
Otherwise, nil and an error from the call to StopInstances.

Types

type Driver

type Driver struct {
	Config aws.Config
	Client *ec2.Client
}

func (Driver) CreateInstances

func (d Driver) CreateInstances(hosts *v1.Hosts, infra *v1.Infra) error

func (Driver) CreateKeyPair

func (d Driver) CreateKeyPair(infra *v1.Infra) error

func (Driver) CreateVolumes

func (d Driver) CreateVolumes(infra *v1.Infra, host *v1.Hosts, disks []v1.Disk) error

func (Driver) DeleteInfra

func (d Driver) DeleteInfra(infra *v1.Infra) error

func (Driver) DeleteInstanceByID

func (d Driver) DeleteInstanceByID(_ string, _ *v1.Infra) error

func (Driver) DeleteInstances

func (d Driver) DeleteInstances(hosts *v1.Hosts) error

func (Driver) DeleteKeyPair

func (d Driver) DeleteKeyPair(infra *v1.Infra) error

func (Driver) DeleteVolume

func (d Driver) DeleteVolume(disksID []string) error

func (Driver) GetBlockDeviceMappings

func (d Driver) GetBlockDeviceMappings(hosts *v1.Hosts, rootDeviceName string, infra *v1.Infra) []types.BlockDeviceMapping

GetBlockDeviceMappings generate blockDeviceMappings from hosts

func (Driver) GetInstances

func (d Driver) GetInstances(infra *v1.Infra, status string) ([]v1.Hosts, error)

func (Driver) GetInstancesByLabel

func (d Driver) GetInstancesByLabel(key string, value string, infra *v1.Infra) (*v1.Hosts, error)

func (Driver) GetTags

func (d Driver) GetTags(hosts *v1.Hosts, infra *v1.Infra) []types.Tag

GetTags get tags

func (Driver) GetVolumeTags

func (d Driver) GetVolumeTags(hosts *v1.Hosts, infra *v1.Infra) []types.Tag

GetVolumeTags get tags

func (Driver) ModifyInstances

func (d Driver) ModifyInstances(curHosts *v1.Hosts, desHosts *v1.Hosts) error

func (Driver) ModifyVolume

func (d Driver) ModifyVolume(curDisk *v1.Disk, desDisk *v1.Disk) error

func (Driver) StopInstances

func (d Driver) StopInstances(hosts *v1.Hosts) error

func (Driver) WaitInstanceRunning

func (d Driver) WaitInstanceRunning(instances []types.Instance) error

WaitInstanceRunning retry for wait instance running

type EC2CreateInstanceAPI

type EC2CreateInstanceAPI interface {
	RunInstances(ctx context.Context,
		params *ec2.RunInstancesInput,
		optFns ...func(*ec2.Options)) (*ec2.RunInstancesOutput, error)

	CreateTags(ctx context.Context,
		params *ec2.CreateTagsInput,
		optFns ...func(*ec2.Options)) (*ec2.CreateTagsOutput, error)

	CreateKeyPair(ctx context.Context,
		params *ec2.CreateKeyPairInput,
		optFns ...func(*ec2.Options)) (*ec2.CreateKeyPairOutput, error)
}

EC2CreateInstanceAPI defines the interface for the RunInstances and CreateTags functions. We use this interface to test the functions using a mocked service.

type EC2CreateVolumeAPI

type EC2CreateVolumeAPI interface {
	CreateVolume(ctx context.Context,
		params *ec2.CreateVolumeInput,
		optFns ...func(*ec2.Options)) (*ec2.CreateVolumeOutput, error)

	AttachVolume(ctx context.Context,
		params *ec2.AttachVolumeInput,
		optFns ...func(*ec2.Options)) (*ec2.AttachVolumeOutput, error)
}

type EC2DeleteVolumeAPI

type EC2DeleteVolumeAPI interface {
	DeleteVolume(ctx context.Context,
		params *ec2.DeleteVolumeInput,
		optFns ...func(*ec2.Options)) (*ec2.DeleteVolumeOutput, error)

	DetachVolume(ctx context.Context,
		params *ec2.DetachVolumeInput,
		optFns ...func(*ec2.Options)) (*ec2.DetachVolumeOutput, error)
}

type EC2DescribeAMIAPI

type EC2DescribeAMIAPI interface {
	DescribeImages(ctx context.Context,
		params *ec2.DescribeImagesInput,
		optFns ...func(*ec2.Options)) (*ec2.DescribeImagesOutput, error)
}

EC2DescribeAMIAPI defines the interface for the DescribeInstances function. We use this interface to test the function using a mocked service.

type EC2DescribeInstancesAPI

type EC2DescribeInstancesAPI interface {
	DescribeInstances(ctx context.Context,
		params *ec2.DescribeInstancesInput,
		optFns ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)
	DescribeInstanceStatus(ctx context.Context,
		params *ec2.DescribeInstanceStatusInput,
		optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceStatusOutput, error)
	CreateTags(ctx context.Context,
		params *ec2.CreateTagsInput,
		optFns ...func(*ec2.Options)) (*ec2.CreateTagsOutput, error)
}

EC2DescribeInstancesAPI defines the interface for the DescribeInstances function. We use this interface to test the function using a mocked service.

type EC2DescribeVolumesAPI

type EC2DescribeVolumesAPI interface {
	DescribeVolumes(ctx context.Context,
		params *ec2.DescribeVolumesInput,
		optFns ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error)
}

EC2DescribeVolumesAPI defines the interface for the DescribeVolumes function. We use this interface to test the function using a mocked service.

type EC2ModifyInstancesAPI

type EC2ModifyInstancesAPI interface {
	ModifyInstanceAttribute(ctx context.Context,
		params *ec2.ModifyInstanceAttributeInput,
		optFns ...func(*ec2.Options)) (*ec2.ModifyInstanceAttributeOutput, error)
	StartInstances(ctx context.Context,
		params *ec2.StartInstancesInput,
		optFns ...func(*ec2.Options)) (*ec2.StartInstancesOutput, error)
}

type EC2ModifyVolumeAPI

type EC2ModifyVolumeAPI interface {
	ModifyVolume(ctx context.Context,
		params *ec2.ModifyVolumeInput,
		optFns ...func(*ec2.Options)) (*ec2.ModifyVolumeOutput, error)
}

type EC2StopInstancesAPI

type EC2StopInstancesAPI interface {
	StopInstances(ctx context.Context,
		params *ec2.StopInstancesInput,
		optFns ...func(*ec2.Options)) (*ec2.StopInstancesOutput, error)
	DeleteKeyPair(ctx context.Context,
		params *ec2.DeleteKeyPairInput,
		optFns ...func(*ec2.Options)) (*ec2.DeleteKeyPairOutput, error)
	DescribeVolumes(ctx context.Context,
		params *ec2.DescribeVolumesInput,
		optFns ...func(*ec2.Options)) (*ec2.DescribeVolumesOutput, error)
}

EC2StopInstancesAPI defines the interface for the StopInstances function. We use this interface to test the function using a mocked service.

type GarbageCollector

type GarbageCollector struct {
	// contains filtered or unexported fields
}

func NewGarbageCollector

func NewGarbageCollector() (*GarbageCollector, error)

func (*GarbageCollector) InstanceGC

func (g *GarbageCollector) InstanceGC() error

func (*GarbageCollector) KeyPairGC

func (g *GarbageCollector) KeyPairGC() error

list and delete users' key pair

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL