Skip to content

Instantly share code, notes, and snippets.

@hassaku63
Created December 25, 2022 10:42
Show Gist options
  • Save hassaku63/0075ac495c0354ecb549e05acd7784ac to your computer and use it in GitHub Desktop.
Save hassaku63/0075ac495c0354ecb549e05acd7784ac to your computer and use it in GitHub Desktop.
AWS SDK for Go 使ってみる
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/sts"
)
func main() {
region := "ap-northeast-1"
sess := session.Must(session.NewSession(&aws.Config{Region: &region}))
// lambda
var lambdaClient *lambda.Lambda = lambda.New(sess)
var functions *lambda.ListFunctionsOutput
var err error
functions, err = lambdaClient.ListFunctions(&lambda.ListFunctionsInput{})
if err != nil {
log.Fatal(err)
}
fmt.Println(len(functions.Functions), " functions found.")
for _, fn := range functions.Functions {
// fmt.Println(fn.String())
switch *fn.PackageType {
case "Image":
fun, err := lambdaClient.GetFunction(&lambda.GetFunctionInput{
FunctionName: fn.FunctionName,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(*fn.FunctionName, ":\n Image: ", *fun.Code.ImageUri)
case "Zip":
fmt.Println(*fn.FunctionName, "\n Runtime: ", *fn.Runtime)
}
}
fmt.Println("lambda functions have printed")
// support
// var supportClient *support.Support = support.New(sess)
// var ret2 *support.DescribeCasesOutput
// ret2, err = supportClient.DescribeCases(&support.DescribeCasesInput{})
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("cases = ", len(ret2.Cases))
// for _, cs := range ret2.Cases {
// fmt.Println(cs.String())
// }
// sts
stsClient := sts.New(sess)
var ret3 *sts.GetCallerIdentityOutput
ret3, err = stsClient.GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err != nil {
log.Fatal(err)
}
fmt.Println(ret3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment