Skip to content
Permalink
Browse files

add guard against `up stack plan` before `up`

behaviour of this is undefined at the moment, plan/apply should
be used for making resource changes, but it is not as obvious
as it could be
  • Loading branch information...
tj committed Apr 16, 2018
1 parent 34b201e commit ce5c6d3ad65ef6866ac429ea28ae9fad48878d5c
Showing with 34 additions and 1 deletion.
  1. +11 −1 internal/cli/stack/stack.go
  2. +3 −0 platform.go
  3. +20 −0 platform/lambda/lambda.go
@@ -38,9 +38,19 @@ func plan(cmd *kingpin.Cmd) {
}

stats.Track("Plan Stack", nil)
region := c.Regions[0]

ok, err := p.Exists(region)
if err != nil {
return errors.Wrap(err, "checking if app exists")
}

if !ok {
return errors.New("Application does not exist, please run `$ up` initially to create it.")
}

// TODO: multi-region
return p.PlanStack(c.Regions[0])
return p.PlanStack(region)
})
}

@@ -74,6 +74,9 @@ type Platform interface {
// empty string.
URL(region, stage string) (string, error)

// Exists returns true if the application has been created.
Exists(region string) (bool, error)

CreateStack(region, version string) error
DeleteStack(region string, wait bool) error
ShowStack(region string) error
@@ -311,6 +311,26 @@ func (p *Platform) ApplyStack(region string) error {
return stack.New(p.config, p.events, nil, region).Apply()
}

// Exists implementation.
func (p *Platform) Exists(region string) (bool, error) {
log.Debug("checking if application exists")
c := lambda.New(session.New(aws.NewConfig().WithRegion(region)))

_, err := c.GetFunctionConfiguration(&lambda.GetFunctionConfigurationInput{
FunctionName: &p.config.Name,
})

if util.IsNotFound(err) {
return false, nil
}

if err != nil {
return false, err
}

return true, nil
}

// getAliasVersions returns the function alias versions.
func (p *Platform) getAliasVersions(region string) (resources.Versions, error) {
var g errgroup.Group

1 comment on commit ce5c6d3

@paul-christmann

This comment has been minimized.

Copy link

paul-christmann commented on ce5c6d3 Apr 17, 2018

Thanks! Fantastic turn-around time!

Please sign in to comment.
You can’t perform that action at this time.