Created
December 9, 2022 04:19
-
-
Save niski84/1efb552e6dd63e49bbde9f1558b4c5f4 to your computer and use it in GitHub Desktop.
This program uses the aws-sdk-go library to call the AWS Pricing API and retrieve the proposed costs for a t2.micro EC2 instance.
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
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/pricing" | |
) | |
func main() { | |
// Create a new AWS session | |
sess := session.Must(session.NewSession()) | |
// Create a new Pricing client | |
pricingSvc := pricing.New(sess) | |
// Set parameters for the GetProducts API call | |
params := &pricing.GetProductsInput{ | |
ServiceCode: aws.String("AmazonEC2"), | |
Filters: []*pricing.Filter{ | |
{ | |
Type: aws.String("TERM_MATCH"), | |
Field: aws.String("instanceType"), | |
Value: aws.String("t2.micro"), | |
}, | |
}, | |
} | |
// Call the GetProducts API | |
result, err := pricingSvc.GetProducts(params) | |
if err != nil { | |
fmt.Println(err.Error()) | |
os.Exit(1) | |
} | |
// Print the proposed costs | |
fmt.Println(result.PriceList) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment