MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / runAWSCmd

Function runAWSCmd

src/cmd/linuxkit/run_aws.go:27–214  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25)
26
27func runAWSCmd() *cobra.Command {
28 var (
29 machineFlag string
30 diskSizeFlag int
31 diskTypeFlag string
32 zoneFlag string
33 sgFlag string
34
35 data string
36 dataPath string
37 )
38 cmd := &cobra.Command{
39 Use: "aws",
40 Short: "launch an AWS ec2 instance using an existing image",
41 Long: `Launch an AWS ec2 instance using an existing image.
42 'name' is the name of an AWS image that has already been uploaded to S3.
43 `,
44 Args: cobra.ExactArgs(1),
45 RunE: func(cmd *cobra.Command, args []string) error {
46 name := args[0]
47
48 if data != "" && dataPath != "" {
49 log.Fatal("Cannot specify both -data and -data-file")
50 }
51
52 if dataPath != "" {
53 dataB, err := os.ReadFile(dataPath)
54 if err != nil {
55 return fmt.Errorf("unable to read metadata file: %v", err)
56 }
57 data = string(dataB)
58 }
59 // data must be base64 encoded
60 data = base64.StdEncoding.EncodeToString([]byte(data))
61
62 machine := getStringValue(awsMachineVar, machineFlag, defaultAWSMachine)
63 diskSize := getIntValue(awsDiskSizeVar, diskSizeFlag, defaultAWSDiskSize)
64 diskType := getStringValue(awsDiskTypeVar, diskTypeFlag, defaultAWSDiskType)
65 zone := os.Getenv("AWS_REGION") + getStringValue(awsZoneVar, zoneFlag, defaultAWSZone)
66
67 sess := session.Must(session.NewSession())
68 compute := ec2.New(sess)
69
70 // 1. Find AMI
71 filter := &ec2.DescribeImagesInput{
72 Filters: []*ec2.Filter{
73 {
74 Name: aws.String("name"),
75 Values: []*string{aws.String(name)},
76 },
77 },
78 }
79 results, err := compute.DescribeImages(filter)
80 if err != nil {
81 return fmt.Errorf("unable to describe images: %s", err)
82 }
83 if len(results.Images) < 1 {
84 return fmt.Errorf("unable to find image with name %s", name)

Callers 1

runCmdFunction · 0.85

Calls 3

getStringValueFunction · 0.85
getIntValueFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected