-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Cloud-Code-AI/14-add-support-for-ec2-inst…
…ances Added Get EC2 Instance Support
- Loading branch information
Showing
5 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package awshandler | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Cloud-Code-AI/cloudstate/services/utils" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
) | ||
|
||
type ec2List struct { | ||
Instances []types.Instance `json:"Instances"` | ||
} | ||
|
||
// Gets all the lambda functions for a given regions and | ||
// stores the results in output/{region}/lambda/functions.json file | ||
func ListEc2Fn(sdkConfig aws.Config) { | ||
const maxItems = 50 | ||
|
||
// Create Lambda service client | ||
client := ec2.NewFromConfig(sdkConfig) | ||
|
||
// Retrieve the instances | ||
result, err := client.DescribeInstances(context.TODO(), &ec2.DescribeInstancesInput{}) | ||
if err != nil { | ||
log.Fatalf("Unable to retrieve instances, %v", err) | ||
} | ||
var instances []types.Instance | ||
// Process and print the instances details | ||
for _, reservation := range result.Reservations { | ||
for _, instance := range reservation.Instances { | ||
instances = append(instances, instance) | ||
} | ||
} | ||
|
||
const ( | ||
path = "/ec2/instances.json" | ||
) | ||
|
||
output := ec2List{ | ||
Instances: instances, | ||
} | ||
|
||
filepath := parentpath + sdkConfig.Region + path | ||
|
||
err = utils.WriteJSONToFile(filepath, output) | ||
if err != nil { | ||
fmt.Println("Error writing lambda function lists") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters