Skip to content

Commit

Permalink
init --function-url creates a default file
Browse files Browse the repository at this point in the history
When a function is not found, init --function-url
creates a default function url config file.
  • Loading branch information
fujiwara committed Feb 5, 2024
1 parent 2c57e8c commit 4ead6bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions functionurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,24 @@ func (app *App) calcFunctionURLPermissionsDiff(ctx context.Context, fc *Function
return adds, removes, nil
}

func (app *App) initFunctionURL(ctx context.Context, fn *Function, opt *InitOption) error {
func (app *App) initFunctionURL(ctx context.Context, fn *Function, exists bool, opt *InitOption) error {
fc, err := app.lambda.GetFunctionUrlConfig(ctx, &lambda.GetFunctionUrlConfigInput{
FunctionName: fn.FunctionName,
Qualifier: opt.Qualifier,
})
if err != nil {
var nfe *types.ResourceNotFoundException
if errors.As(err, &nfe) {
log.Printf("[warn] function url config for %s not found", *fn.FunctionName)
return nil
if exists {
log.Printf("[warn] function url config for %s not found", *fn.FunctionName)
return nil
} else {
log.Printf("[info] initializing function url config for %s", *fn.FunctionName)
// default settings will be used
fc = &lambda.GetFunctionUrlConfigOutput{
AuthType: types.FunctionUrlAuthTypeNone,
}
}
} else {
return fmt.Errorf("failed to get function url config: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (app *App) Init(ctx context.Context, opt *InitOption) error {
}

if opt.FunctionURL {
if err := app.initFunctionURL(ctx, fn, opt); err != nil {
if err := app.initFunctionURL(ctx, fn, exists, opt); err != nil {
return err
}
}
Expand Down

0 comments on commit 4ead6bf

Please # to comment.