diff --git a/README.md b/README.md index ad5e56c..cdabf1d 100644 --- a/README.md +++ b/README.md @@ -183,18 +183,24 @@ usage: lambroll deploy [] deploy or create function Flags: + --help Show context-sensitive help (also try --help-long + and --help-man). + --log-level=info log level (trace, debug, info, warn, error) --function="function.json" Function file path - --profile="$AWS_PROFILE" AWS credential profile name - --region="$AWS_REGION" AWS region + --profile="" AWS credential profile name + --region="" AWS region --tfstate="" URL to terraform.tfstate --endpoint="" AWS API Lambda Endpoint + --envfile=ENVFILE ... environment files --src="." function zip archive or src dir - --exclude-file=".lambdaignore" + --exclude-file=".lambdaignore" exclude file --dry-run dry run --publish publish function --alias="current" alias name for publish - --skip-archive skip to create zip archive. requires Code.S3Bucket and Code.S3Key in function definition + --alias-to-latest set alias to unpublished $LATEST version + --skip-archive skip to create zip archive. requires Code.S3Bucket + and Code.S3Key in function definition ``` `deploy` works as below. diff --git a/cmd/lambroll/main.go b/cmd/lambroll/main.go index 03fb354..7a54e00 100644 --- a/cmd/lambroll/main.go +++ b/cmd/lambroll/main.go @@ -47,6 +47,7 @@ func _main() int { DryRun: deploy.Flag("dry-run", "dry run").Bool(), Publish: deploy.Flag("publish", "publish function").Default("true").Bool(), AliasName: deploy.Flag("alias", "alias name for publish").Default(lambroll.CurrentAliasName).String(), + AliasToLatest: deploy.Flag("alias-to-latest", "set alias to unpublished $LATEST version").Default("false").Bool(), SkipArchive: deploy.Flag("skip-archive", "skip to create zip archive. requires Code.S3Bucket and Code.S3Key in function definition").Default("false").Bool(), } diff --git a/deploy.go b/deploy.go index c6bab2f..0d35ea9 100644 --- a/deploy.go +++ b/deploy.go @@ -22,6 +22,7 @@ type DeployOption struct { ExcludeFile *string Publish *bool AliasName *string + AliasToLatest *bool DryRun *bool SkipArchive *bool } @@ -152,13 +153,16 @@ func (app *App) Deploy(opt DeployOption) error { newerVersion = *res.Version log.Printf("[info] deployed version %s %s", *res.Version, opt.label()) } else { - log.Println("[info] deployed") + newerVersion = versionLatest + log.Printf("[info] deployed version %s %s", newerVersion, opt.label()) } - if *opt.DryRun || !*opt.Publish { + if *opt.DryRun { return nil } - - return app.updateAliases(*fn.FunctionName, versionAlias{newerVersion, *opt.AliasName}) + if *opt.Publish || *opt.AliasToLatest { + return app.updateAliases(*fn.FunctionName, versionAlias{newerVersion, *opt.AliasName}) + } + return nil } func (app *App) updateFunctionCodeWithRetry(ctx context.Context, in *lambda.UpdateFunctionCodeInput) (*lambda.FunctionConfiguration, error) { diff --git a/lambroll.go b/lambroll.go index 33458bb..85bacf8 100644 --- a/lambroll.go +++ b/lambroll.go @@ -18,6 +18,8 @@ import ( "github.com/shogo82148/go-retry" ) +const versionLatest = "$LATEST" + var retryPolicy = retry.Policy{ MinDelay: time.Second, MaxDelay: 5 * time.Second,