diff --git a/archive.go b/archive.go index 3dc3dd8..68e4dc2 100644 --- a/archive.go +++ b/archive.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -62,7 +61,7 @@ func loadZipArchive(src string) (*os.File, os.FileInfo, error) { // createZipArchive creates a zip archive func createZipArchive(src string, excludes []string) (*os.File, os.FileInfo, error) { log.Printf("[info] creating zip archive from %s", src) - tmpfile, err := ioutil.TempFile("", "archive") + tmpfile, err := os.CreateTemp("", "archive") if err != nil { return nil, nil, fmt.Errorf("failed to open tempFile: %w", err) } diff --git a/create.go b/create.go index ff43dc3..94471b1 100644 --- a/create.go +++ b/create.go @@ -8,8 +8,8 @@ import ( "os" "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) var directUploadThreshold = int64(50 * 1024 * 1024) // 50MB @@ -34,7 +34,7 @@ func prepareZipfile(src string, excludes []string) (*os.File, os.FileInfo, error } func (app *App) prepareFunctionCodeForDeploy(opt DeployOption, fn *FunctionV2) error { - if fn.PackageType == lambdav2types.PackageTypeImage { + if fn.PackageType == types.PackageTypeImage { if fn.Code == nil || fn.Code.ImageUri == nil { return fmt.Errorf("PackageType=Image requires Code.ImageUri in function definition") } @@ -42,7 +42,7 @@ func (app *App) prepareFunctionCodeForDeploy(opt DeployOption, fn *FunctionV2) e log.Printf("[info] using docker image %s", *fn.Code.ImageUri) if fn.ImageConfig == nil { - fn.ImageConfig = &lambdav2types.ImageConfig{} // reset explicitly + fn.ImageConfig = &types.ImageConfig{} // reset explicitly } return nil } @@ -86,7 +86,7 @@ func (app *App) prepareFunctionCodeForDeploy(opt DeployOption, fn *FunctionV2) e if err != nil { return fmt.Errorf("failed to read zipfile content: %w", err) } - fn.Code = &lambdav2types.FunctionCode{ZipFile: b} + fn.Code = &types.FunctionCode{ZipFile: b} } return nil } @@ -124,7 +124,7 @@ func (app *App) create(opt DeployOption, fn *FunctionV2) error { log.Printf("[info] creating alias set %s to version %s %s", *opt.AliasName, version, opt.label()) if !*opt.DryRun { - _, err := app.lambdav2.CreateAlias(ctx, &lambdav2.CreateAliasInput{ + _, err := app.lambda.CreateAlias(ctx, &lambda.CreateAliasInput{ FunctionName: fn.FunctionName, FunctionVersion: aws.String(version), Name: aws.String(*opt.AliasName), @@ -137,8 +137,8 @@ func (app *App) create(opt DeployOption, fn *FunctionV2) error { return nil } -func (app *App) createFunction(ctx context.Context, fn *lambdav2.CreateFunctionInput) (*lambdav2.CreateFunctionOutput, error) { - if res, err := app.lambdav2.CreateFunction(ctx, fn); err != nil { +func (app *App) createFunction(ctx context.Context, fn *lambda.CreateFunctionInput) (*lambda.CreateFunctionOutput, error) { + if res, err := app.lambda.CreateFunction(ctx, fn); err != nil { return nil, fmt.Errorf("failed to create function: %w", err) } else { return res, app.waitForLastUpdateStatusSuccessful(ctx, *fn.FunctionName) diff --git a/delete.go b/delete.go index 95dcfab..fbdba03 100644 --- a/delete.go +++ b/delete.go @@ -5,7 +5,7 @@ import ( "fmt" "log" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda" ) // DeleteOption represents options for Delete() @@ -34,7 +34,7 @@ func (app *App) Delete(opt DeleteOption) error { if *opt.DryRun { return nil } - _, err = app.lambdav2.DeleteFunction(ctx, &lambdav2.DeleteFunctionInput{ + _, err = app.lambda.DeleteFunction(ctx, &lambda.DeleteFunctionInput{ FunctionName: fn.FunctionName, }) if err != nil { diff --git a/deploy.go b/deploy.go index 4aa41a1..b60ad1d 100644 --- a/deploy.go +++ b/deploy.go @@ -6,13 +6,12 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "log" "os" "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) // DeployOption represens an option for Deploy() @@ -43,7 +42,7 @@ type versionAlias struct { // Expand expands ExcludeFile contents to Excludes func expandExcludeFile(file string) ([]string, error) { - b, err := ioutil.ReadFile(file) + b, err := os.ReadFile(file) if err != nil { if os.IsNotExist(err) { return nil, nil @@ -84,10 +83,10 @@ func (app *App) Deploy(opt DeployOption) error { } log.Printf("[info] starting deploy function %s", *fn.FunctionName) - if current, err := app.lambdav2.GetFunction(ctx, &lambdav2.GetFunctionInput{ + if current, err := app.lambda.GetFunction(ctx, &lambda.GetFunctionInput{ FunctionName: fn.FunctionName, }); err != nil { - var nfe *lambdav2types.ResourceNotFoundException + var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { return app.create(opt, fn) } @@ -102,7 +101,7 @@ func (app *App) Deploy(opt DeployOption) error { } log.Println("[info] updating function configuration", opt.label()) - confIn := &lambdav2.UpdateFunctionConfigurationInput{ + confIn := &lambda.UpdateFunctionConfigurationInput{ DeadLetterConfig: fn.DeadLetterConfig, Description: fn.Description, EphemeralStorage: fn.EphemeralStorage, @@ -121,7 +120,7 @@ func (app *App) Deploy(opt DeployOption) error { SnapStart: fn.SnapStart, } if env := fn.Environment; env == nil || env.Variables == nil { - confIn.Environment = &lambdav2types.Environment{ + confIn.Environment = &types.Environment{ Variables: map[string]string{}, // set empty variables explicitly } } else { @@ -143,7 +142,7 @@ func (app *App) Deploy(opt DeployOption) error { return err } - codeIn := &lambdav2.UpdateFunctionCodeInput{ + codeIn := &lambda.UpdateFunctionCodeInput{ Architectures: fn.Architectures, FunctionName: fn.FunctionName, ZipFile: fn.Code.ZipFile, @@ -158,7 +157,7 @@ func (app *App) Deploy(opt DeployOption) error { codeIn.Publish = *opt.Publish } - var res *lambdav2.UpdateFunctionCodeOutput + var res *lambda.UpdateFunctionCodeOutput proc := func(ctx context.Context) error { var err error // set res outside of this function @@ -190,12 +189,12 @@ func (app *App) Deploy(opt DeployOption) error { return nil } -func (app *App) updateFunctionConfiguration(ctx context.Context, in *lambdav2.UpdateFunctionConfigurationInput) error { +func (app *App) updateFunctionConfiguration(ctx context.Context, in *lambda.UpdateFunctionConfigurationInput) error { retrier := retryPolicy.Start(ctx) for retrier.Continue() { - _, err := app.lambdav2.UpdateFunctionConfiguration(ctx, in) + _, err := app.lambda.UpdateFunctionConfiguration(ctx, in) if err != nil { - var rce *lambdav2types.ResourceConflictException + var rce *types.ResourceConflictException if errors.As(err, &rce) { log.Println("[debug] retrying", rce.Error()) continue @@ -207,14 +206,14 @@ func (app *App) updateFunctionConfiguration(ctx context.Context, in *lambdav2.Up return fmt.Errorf("failed to update function configuration (max retries reached)") } -func (app *App) updateFunctionCode(ctx context.Context, in *lambdav2.UpdateFunctionCodeInput) (*lambdav2.UpdateFunctionCodeOutput, error) { - var res *lambdav2.UpdateFunctionCodeOutput +func (app *App) updateFunctionCode(ctx context.Context, in *lambda.UpdateFunctionCodeInput) (*lambda.UpdateFunctionCodeOutput, error) { + var res *lambda.UpdateFunctionCodeOutput retrier := retryPolicy.Start(ctx) for retrier.Continue() { var err error - res, err = app.lambdav2.UpdateFunctionCode(ctx, in) + res, err = app.lambda.UpdateFunctionCode(ctx, in) if err != nil { - var rce *lambdav2types.ResourceConflictException + var rce *types.ResourceConflictException if errors.As(err, &rce) { log.Println("[debug] retrying", err) continue @@ -245,7 +244,7 @@ func (app *App) ensureLastUpdateStatusSuccessful(ctx context.Context, name strin func (app *App) waitForLastUpdateStatusSuccessful(ctx context.Context, name string) error { retrier := retryPolicy.Start(ctx) for retrier.Continue() { - res, err := app.lambdav2.GetFunction(ctx, &lambdav2.GetFunctionInput{ + res, err := app.lambda.GetFunction(ctx, &lambda.GetFunctionInput{ FunctionName: aws.String(name), }) if err != nil { @@ -255,10 +254,10 @@ func (app *App) waitForLastUpdateStatusSuccessful(ctx context.Context, name stri state := res.Configuration.State last := res.Configuration.LastUpdateStatus log.Printf("[info] State:%s LastUpdateStatus:%s", state, last) - if last == lambdav2types.LastUpdateStatusSuccessful { + if last == types.LastUpdateStatusSuccessful { return nil } - log.Printf("[info] waiting for LastUpdateStatus %s", lambdav2types.LastUpdateStatusSuccessful) + log.Printf("[info] waiting for LastUpdateStatus %s", types.LastUpdateStatusSuccessful) } } return fmt.Errorf("max retries reached") @@ -268,16 +267,16 @@ func (app *App) updateAliases(functionName string, vs ...versionAlias) error { ctx := context.TODO() for _, v := range vs { log.Printf("[info] updating alias set %s to version %s", v.Name, v.Version) - _, err := app.lambdav2.UpdateAlias(ctx, &lambdav2.UpdateAliasInput{ + _, err := app.lambda.UpdateAlias(ctx, &lambda.UpdateAliasInput{ FunctionName: aws.String(functionName), FunctionVersion: aws.String(v.Version), Name: aws.String(v.Name), }) if err != nil { - var nfe *lambdav2types.ResourceNotFoundException + var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { log.Printf("[info] alias %s is not found. creating alias", v.Name) - _, err := app.lambdav2.CreateAlias(ctx, &lambdav2.CreateAliasInput{ + _, err := app.lambda.CreateAlias(ctx, &lambda.CreateAliasInput{ FunctionName: aws.String(functionName), FunctionVersion: aws.String(v.Version), Name: aws.String(v.Name), @@ -301,14 +300,14 @@ func (app *App) deleteVersions(functionName string, keepVersions int) error { return nil } - params := &lambdav2.ListVersionsByFunctionInput{ + params := &lambda.ListVersionsByFunctionInput{ FunctionName: aws.String(functionName), } // versions will be set asc order, like 1 to N - versions := []lambdav2types.FunctionConfiguration{} + versions := []types.FunctionConfiguration{} for { - res, err := app.lambdav2.ListVersionsByFunction(ctx, params) + res, err := app.lambda.ListVersionsByFunction(ctx, params) if err != nil { return fmt.Errorf("failed to list versions: %w", err) } @@ -330,7 +329,7 @@ func (app *App) deleteVersions(functionName string, keepVersions int) error { } log.Printf("[info] deleting function version: %s", *v.Version) - _, err := app.lambdav2.DeleteFunction(ctx, &lambdav2.DeleteFunctionInput{ + _, err := app.lambda.DeleteFunction(ctx, &lambda.DeleteFunctionInput{ FunctionName: aws.String(functionName), Qualifier: v.Version, }) diff --git a/diff.go b/diff.go index 12e882b..e4cb85a 100644 --- a/diff.go +++ b/diff.go @@ -12,8 +12,8 @@ import ( "github.com/kylelemons/godebug/diff" awsv2 "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) // DiffOption represents options for Diff() @@ -41,13 +41,13 @@ func (app *App) Diff(opt DiffOption) error { fillDefaultValuesV2(newFunc) name := *newFunc.FunctionName - var latest *lambdav2types.FunctionConfiguration - var code *lambdav2types.FunctionCodeLocation + var latest *types.FunctionConfiguration + var code *types.FunctionCodeLocation var tags TagsV2 var currentCodeSha256 string - var packageType lambdav2types.PackageType - if res, err := app.lambdav2.GetFunction(ctx, &lambdav2.GetFunctionInput{ + var packageType types.PackageType + if res, err := app.lambda.GetFunction(ctx, &lambda.GetFunctionInput{ FunctionName: &name, }); err != nil { return fmt.Errorf("failed to GetFunction %s: %w", name, err) @@ -74,7 +74,7 @@ func (app *App) Diff(opt DiffOption) error { } if awsv2.ToBool(opt.CodeSha256) { - if packageType != lambdav2types.PackageTypeZip { + if packageType != types.PackageTypeZip { return fmt.Errorf("code-sha256 is only supported for Zip package type") } zipfile, _, err := prepareZipfile(*opt.Src, opt.Excludes) diff --git a/function_test.go b/function_test.go index 9ec0274..51649d4 100644 --- a/function_test.go +++ b/function_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/aws" - types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) func TestLoadFunction(t *testing.T) { diff --git a/init.go b/init.go index 7eedbab..8cd381c 100644 --- a/init.go +++ b/init.go @@ -11,8 +11,8 @@ import ( "strings" awsv2 "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) // InitOption represents options for Init() @@ -24,19 +24,19 @@ type InitOption struct { // Init initializes function.json func (app *App) Init(opt InitOption) error { ctx := context.TODO() - res, err := app.lambdav2.GetFunction(ctx, &lambdav2.GetFunctionInput{ + res, err := app.lambda.GetFunction(ctx, &lambda.GetFunctionInput{ FunctionName: opt.FunctionName, }) - var c *lambdav2types.FunctionConfiguration + var c *types.FunctionConfiguration exists := true if err != nil { - var nfe *lambdav2types.ResourceNotFoundException + var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { log.Printf("[info] function %s is not found", *opt.FunctionName) - c = &lambdav2types.FunctionConfiguration{ + c = &types.FunctionConfiguration{ FunctionName: opt.FunctionName, MemorySize: awsv2.Int32(128), - Runtime: lambdav2types.RuntimeNodejs18x, + Runtime: types.RuntimeNodejs18x, Timeout: awsv2.Int32(3), Handler: awsv2.String("index.handler"), Role: awsv2.String( @@ -60,7 +60,7 @@ func (app *App) Init(opt InitOption) error { if exists { arn := app.functionArn(*c.FunctionName) log.Printf("[debug] listing tags of %s", arn) - res, err := app.lambdav2.ListTags(ctx, &lambdav2.ListTagsInput{ + res, err := app.lambda.ListTags(ctx, &lambda.ListTagsInput{ Resource: awsv2.String(arn), }) if err != nil { diff --git a/invoke.go b/invoke.go index 8b96753..9a1396b 100644 --- a/invoke.go +++ b/invoke.go @@ -12,8 +12,8 @@ import ( "github.com/mattn/go-isatty" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdatypesv2 "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + typesv2 "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) // InvokeOption represents option for Invoke() @@ -31,15 +31,15 @@ func (app *App) Invoke(opt InvokeOption) error { if err != nil { return fmt.Errorf("failed to load function: %w", err) } - var invocationType lambdatypesv2.InvocationType - var logType lambdatypesv2.LogType + var invocationType typesv2.InvocationType + var logType typesv2.LogType if *opt.Async { - invocationType = lambdatypesv2.InvocationTypeEvent + invocationType = typesv2.InvocationTypeEvent } else { - invocationType = lambdatypesv2.InvocationTypeRequestResponse + invocationType = typesv2.InvocationTypeRequestResponse } if *opt.LogTail { - logType = lambdatypesv2.LogTypeTail + logType = typesv2.LogTypeTail } if isatty.IsTerminal(os.Stdin.Fd()) { @@ -60,7 +60,7 @@ PAYLOAD: return fmt.Errorf("failed to decode payload as JSON: %w", err) } b, _ := json.Marshal(payload) - in := &lambdav2.InvokeInput{ + in := &lambda.InvokeInput{ FunctionName: fn.FunctionName, InvocationType: invocationType, LogType: logType, @@ -70,7 +70,7 @@ PAYLOAD: in.Qualifier = opt.Qualifier } log.Println("[debug] invoking function", in) - res, err := app.lambdav2.Invoke(ctx, in) + res, err := app.lambda.Invoke(ctx, in) if err != nil { log.Println("[error] failed to invoke function", err.Error()) continue PAYLOAD diff --git a/lambroll.go b/lambroll.go index 32c170e..2a2d643 100644 --- a/lambroll.go +++ b/lambroll.go @@ -17,11 +17,11 @@ import ( awsv2 "github.com/aws/aws-sdk-go-v2/aws" configv2 "github.com/aws/aws-sdk-go-v2/config" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda" s3v2 "github.com/aws/aws-sdk-go-v2/service/s3" stsv2 "github.com/aws/aws-sdk-go-v2/service/sts" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) const versionLatest = "$LATEST" @@ -36,7 +36,7 @@ var retryPolicy = retry.Policy{ // Function represents configuration of Lambda function //type Function = lambda.CreateFunctionInput -type FunctionV2 = lambdav2.CreateFunctionInput +type FunctionV2 = lambda.CreateFunctionInput // Tags represents tags of function type Tags = map[string]*string @@ -87,7 +87,7 @@ type App struct { loader *config.Loader awsv2Config awsv2.Config - lambdav2 *lambdav2.Client + lambda *lambda.Client extStr map[string]string extCode map[string]string @@ -103,7 +103,7 @@ func newAwsV2Config(ctx context.Context, opt *Option) (awsv2.Config, error) { } if opt.Endpoint != nil && *opt.Endpoint != "" { customResolver := awsv2.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (awsv2.Endpoint, error) { - if service == lambdav2.ServiceID || service == stsv2.ServiceID || service == s3v2.ServiceID { + if service == lambda.ServiceID || service == stsv2.ServiceID || service == s3v2.ServiceID { return awsv2.Endpoint{ PartitionID: "aws", URL: *opt.Endpoint, @@ -171,7 +171,7 @@ func New(ctx context.Context, opt *Option) (*App, error) { loader: loader, awsv2Config: v2cfg, - lambdav2: lambdav2.NewFromConfig(v2cfg), + lambda: lambda.NewFromConfig(v2cfg), } if opt.ExtStr != nil { app.extStr = *opt.ExtStr @@ -234,7 +234,7 @@ func (app *App) loadFunctionV2(path string) (*FunctionV2, error) { return &fn, nil } -func newFunctionFromV2(c *lambdav2types.FunctionConfiguration, code *lambdav2types.FunctionCodeLocation, tags TagsV2) *FunctionV2 { +func newFunctionFromV2(c *types.FunctionConfiguration, code *types.FunctionCodeLocation, tags TagsV2) *FunctionV2 { fn := &FunctionV2{ Architectures: c.Architectures, Description: c.Description, @@ -252,13 +252,13 @@ func newFunctionFromV2(c *lambdav2types.FunctionConfiguration, code *lambdav2typ } if e := c.Environment; e != nil { - fn.Environment = &lambdav2types.Environment{ + fn.Environment = &types.Environment{ Variables: e.Variables, } } if i := c.ImageConfigResponse; i != nil { if ic := i.ImageConfig; ic != nil { - fn.ImageConfig = &lambdav2types.ImageConfig{ + fn.ImageConfig = &types.ImageConfig{ Command: i.ImageConfig.Command, EntryPoint: i.ImageConfig.EntryPoint, WorkingDirectory: i.ImageConfig.WorkingDirectory, @@ -269,21 +269,21 @@ func newFunctionFromV2(c *lambdav2types.FunctionConfiguration, code *lambdav2typ fn.Layers = append(fn.Layers, *layer.Arn) } if t := c.TracingConfig; t != nil { - fn.TracingConfig = &lambdav2types.TracingConfig{ + fn.TracingConfig = &types.TracingConfig{ Mode: t.Mode, } } if v := c.VpcConfig; v != nil && *v.VpcId != "" { - fn.VpcConfig = &lambdav2types.VpcConfig{ + fn.VpcConfig = &types.VpcConfig{ SubnetIds: v.SubnetIds, SecurityGroupIds: v.SecurityGroupIds, } } - if (code != nil && awsv2.ToString(code.RepositoryType) == "ECR") || fn.PackageType == lambdav2types.PackageTypeImage { + if (code != nil && awsv2.ToString(code.RepositoryType) == "ECR") || fn.PackageType == types.PackageTypeImage { log.Printf("[debug] Image URL=%s", *code.ImageUri) - fn.PackageType = lambdav2types.PackageTypeImage - fn.Code = &lambdav2types.FunctionCode{ + fn.PackageType = types.PackageTypeImage + fn.Code = &types.FunctionCode{ ImageUri: code.ImageUri, } } @@ -295,7 +295,7 @@ func newFunctionFromV2(c *lambdav2types.FunctionConfiguration, code *lambdav2typ func fillDefaultValuesV2(fn *FunctionV2) { if len(fn.Architectures) == 0 { - fn.Architectures = []lambdav2types.Architecture{lambdav2types.ArchitectureX8664} + fn.Architectures = []types.Architecture{types.ArchitectureX8664} } if fn.Description == nil { fn.Description = awsv2.String("") @@ -304,12 +304,12 @@ func fillDefaultValuesV2(fn *FunctionV2) { fn.MemorySize = awsv2.Int32(128) } if fn.TracingConfig == nil { - fn.TracingConfig = &lambdav2types.TracingConfig{ - Mode: lambdav2types.TracingModePassThrough, + fn.TracingConfig = &types.TracingConfig{ + Mode: types.TracingModePassThrough, } } if fn.EphemeralStorage == nil { - fn.EphemeralStorage = &lambdav2types.EphemeralStorage{ + fn.EphemeralStorage = &types.EphemeralStorage{ Size: awsv2.Int32(512), } } @@ -317,17 +317,17 @@ func fillDefaultValuesV2(fn *FunctionV2) { fn.Timeout = awsv2.Int32(3) } if fn.SnapStart == nil { - fn.SnapStart = &lambdav2types.SnapStart{ - ApplyOn: lambdav2types.SnapStartApplyOnNone, + fn.SnapStart = &types.SnapStart{ + ApplyOn: types.SnapStartApplyOnNone, } } } -func newSnapStartV2(s *lambdav2types.SnapStartResponse) *lambdav2types.SnapStart { +func newSnapStartV2(s *types.SnapStartResponse) *types.SnapStart { if s == nil { return nil } - return &lambdav2types.SnapStart{ + return &types.SnapStart{ ApplyOn: s.ApplyOn, } } @@ -355,7 +355,7 @@ func exportEnvFile(file string) error { var errCannotUpdateImageAndZip = fmt.Errorf("cannot update function code between Image and Zip") -func validateUpdateFunctionV2(currentConf *lambdav2types.FunctionConfiguration, currentCode *lambdav2types.FunctionCodeLocation, newFn *lambdav2.CreateFunctionInput) error { +func validateUpdateFunctionV2(currentConf *types.FunctionConfiguration, currentCode *types.FunctionCodeLocation, newFn *lambda.CreateFunctionInput) error { newCode := newFn.Code // new=Image @@ -367,7 +367,7 @@ func validateUpdateFunctionV2(currentConf *lambdav2types.FunctionConfiguration, } // current=Image - if currentCode != nil && currentCode.ImageUri != nil || currentConf.PackageType == lambdav2types.PackageTypeImage { + if currentCode != nil && currentCode.ImageUri != nil || currentConf.PackageType == types.PackageTypeImage { // new=Zip if newCode == nil || newCode.ImageUri == nil { return errCannotUpdateImageAndZip diff --git a/list.go b/list.go index d73d5e7..947a128 100644 --- a/list.go +++ b/list.go @@ -7,7 +7,7 @@ import ( "os" "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda" ) // ListOption represents options for List() @@ -19,7 +19,7 @@ func (app *App) List(opt ListOption) error { ctx := context.TODO() var marker *string for { - res, err := app.lambdav2.ListFunctions(ctx, &lambdav2.ListFunctionsInput{ + res, err := app.lambda.ListFunctions(ctx, &lambda.ListFunctionsInput{ MaxItems: aws.Int32(50), }) if err != nil { @@ -28,7 +28,7 @@ func (app *App) List(opt ListOption) error { for _, c := range res.Functions { arn := app.functionArn(*c.FunctionName) log.Printf("[debug] listing tags of %s", arn) - res, err := app.lambdav2.ListTags(ctx, &lambdav2.ListTagsInput{ + res, err := app.lambda.ListTags(ctx, &lambda.ListTagsInput{ Resource: aws.String(arn), }) if err != nil { diff --git a/rollback.go b/rollback.go index 063d87a..01ebffb 100644 --- a/rollback.go +++ b/rollback.go @@ -9,8 +9,8 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) // RollbackOption represents option for Rollback() @@ -37,7 +37,7 @@ func (app *App) Rollback(opt RollbackOption) error { log.Printf("[info] starting rollback function %s", *fn.FunctionName) - res, err := app.lambdav2.GetAlias(ctx, &lambdav2.GetAliasInput{ + res, err := app.lambda.GetAlias(ctx, &lambda.GetAliasInput{ FunctionName: fn.FunctionName, Name: aws.String(CurrentAliasName), }) @@ -56,12 +56,12 @@ VERSIONS: for v := cv - 1; v > 0; v-- { log.Printf("[debug] get function version %d", v) vs := strconv.FormatInt(v, 10) - res, err := app.lambdav2.GetFunction(ctx, &lambdav2.GetFunctionInput{ + res, err := app.lambda.GetFunction(ctx, &lambda.GetFunctionInput{ FunctionName: fn.FunctionName, Qualifier: aws.String(vs), }) if err != nil { - var nfe *lambdav2types.ResourceNotFoundException + var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { log.Printf("[debug] version %s not found", vs) continue VERSIONS @@ -96,7 +96,7 @@ func (app *App) deleteFunctionVersion(functionName, version string) error { ctx := context.TODO() for { log.Printf("[debug] checking aliased version") - res, err := app.lambdav2.GetAlias(ctx, &lambdav2.GetAliasInput{ + res, err := app.lambda.GetAlias(ctx, &lambda.GetAliasInput{ FunctionName: aws.String(functionName), Name: aws.String(CurrentAliasName), }) @@ -111,7 +111,7 @@ func (app *App) deleteFunctionVersion(functionName, version string) error { break } log.Printf("[info] deleting function version %s", version) - _, err := app.lambdav2.DeleteFunction(ctx, &lambdav2.DeleteFunctionInput{ + _, err := app.lambda.DeleteFunction(ctx, &lambda.DeleteFunctionInput{ FunctionName: aws.String(functionName), Qualifier: aws.String(version), }) diff --git a/tags.go b/tags.go index 9420250..a072e02 100644 --- a/tags.go +++ b/tags.go @@ -7,8 +7,8 @@ import ( "log" "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) func (app *App) updateTags(fn *FunctionV2, opt DeployOption) error { @@ -18,13 +18,13 @@ func (app *App) updateTags(fn *FunctionV2, opt DeployOption) error { return nil } arn := app.functionArn(*fn.FunctionName) - tags, err := app.lambdav2.ListTags(ctx, &lambdav2.ListTagsInput{ + tags, err := app.lambda.ListTags(ctx, &lambda.ListTagsInput{ Resource: aws.String(arn), }) if err != nil { - var nfe *lambdav2types.ResourceNotFoundException + var nfe *types.ResourceNotFoundException if errors.As(err, &nfe) { - tags, err = &lambdav2.ListTagsOutput{}, nil + tags, err = &lambda.ListTagsOutput{}, nil } else { return fmt.Errorf("failed to list tags of %s: %w", arn, err) } @@ -41,7 +41,7 @@ func (app *App) updateTags(fn *FunctionV2, opt DeployOption) error { if n := len(setTags); n > 0 { log.Printf("[info] setting %d tags %s", n, opt.label()) if !*opt.DryRun { - _, err = app.lambdav2.TagResource(ctx, &lambdav2.TagResourceInput{ + _, err = app.lambda.TagResource(ctx, &lambda.TagResourceInput{ Resource: aws.String(arn), Tags: setTags, }) @@ -54,7 +54,7 @@ func (app *App) updateTags(fn *FunctionV2, opt DeployOption) error { if n := len(removeTagKeys); n > 0 { log.Printf("[info] removing %d tags %s", n, opt.label()) if !*opt.DryRun { - _, err = app.lambdav2.UntagResource(ctx, &lambdav2.UntagResourceInput{ + _, err = app.lambda.UntagResource(ctx, &lambda.UntagResourceInput{ Resource: aws.String(arn), TagKeys: removeTagKeys, }) diff --git a/utils.go b/utils.go index 260b453..5c38fc7 100644 --- a/utils.go +++ b/utils.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "log" "os" "strings" @@ -19,7 +18,7 @@ func (app *App) saveFile(path string, b []byte, mode os.FileMode) error { return nil } } - return ioutil.WriteFile(path, b, mode) + return os.WriteFile(path, b, mode) } func marshalJSONV2(s interface{}) ([]byte, error) { diff --git a/versions.go b/versions.go index 504fdd0..3d58822 100644 --- a/versions.go +++ b/versions.go @@ -11,8 +11,8 @@ import ( "github.com/olekukonko/tablewriter" awsv2 "github.com/aws/aws-sdk-go-v2/aws" - lambdav2 "github.com/aws/aws-sdk-go-v2/service/lambda" - lambdav2types "github.com/aws/aws-sdk-go-v2/service/lambda/types" + "github.com/aws/aws-sdk-go-v2/service/lambda" + "github.com/aws/aws-sdk-go-v2/service/lambda/types" ) // VersionsOption represents options for Versions() @@ -87,7 +87,7 @@ func (app *App) Versions(opt VersionsOption) error { aliases := make(map[string][]string) var nextAliasMarker *string for { - res, err := app.lambdav2.ListAliases(ctx, &lambdav2.ListAliasesInput{ + res, err := app.lambda.ListAliases(ctx, &lambda.ListAliasesInput{ FunctionName: &name, Marker: nextAliasMarker, }) @@ -108,10 +108,10 @@ func (app *App) Versions(opt VersionsOption) error { } } - var versions []lambdav2types.FunctionConfiguration + var versions []types.FunctionConfiguration var nextMarker *string for { - res, err := app.lambdav2.ListVersionsByFunction(ctx, &lambdav2.ListVersionsByFunctionInput{ + res, err := app.lambda.ListVersionsByFunction(ctx, &lambda.ListVersionsByFunctionInput{ FunctionName: &name, Marker: nextMarker, })