// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Logs", map[string]interface{}{ "has_filter": filter != "", "since": duration, "follow": follow, }) if err := root.Project.LoadFunctions(args...); err != nil { return err } config := logs.Config{ Service: cloudwatchlogs.New(root.Session), StartTime: time.Now().Add(-duration).UTC(), PollInterval: 5 * time.Second, Follow: follow, FilterPattern: filter, } l := &logs.Logs{ Config: config, } for _, fn := range root.Project.Functions { l.GroupNames = append(l.GroupNames, fn.GroupName()) } for event := range l.Start() { fmt.Printf("\033[34m%s\033[0m %s", event.GroupName, event.Message) } return l.Err() }
// Run command. func run(c *cobra.Command, args []string) (err error) { stats.Track("Docs", nil) var w io.WriteCloser = os.Stdout if isatty.IsTerminal(os.Stdout.Fd()) { cmd := exec.Command("less", "-R") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr defer cmd.Wait() w, err = cmd.StdinPipe() if err != nil { return err } defer w.Close() if err := cmd.Start(); err != nil { return err } } _, err = io.Copy(w, doc.Reader()) return err }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Deploy", map[string]interface{}{ "concurrency": concurrency, "has_alias": alias != "", "env": len(env), "args": len(args), }) root.Project.Concurrency = concurrency root.Project.Alias = alias if err := root.Project.LoadFunctions(args...); err != nil { return err } for _, fn := range root.Project.Functions { stats.Track("Deploy Function", map[string]interface{}{ "runtime": fn.Runtime, "has_alias": alias != "", "has_env_file": envFile != "", "env": len(env), }) } if envFile != "" { if err := root.Project.LoadEnvFromFile(envFile); err != nil { return fmt.Errorf("reading env file %q: %s", envFile, err) } } vars, err := utils.ParseEnv(env) if err != nil { return err } for k, v := range vars { root.Project.Setenv(k, v) } return root.Project.DeployAndClean() }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Metrics", map[string]interface{}{ "since": duration, }) if err := root.Project.LoadFunctions(args...); err != nil { return err } service := lambda.New(root.Session) config := metrics.Config{ Service: cloudwatch.New(root.Session), StartDate: time.Now().UTC().Add(-duration), EndDate: time.Now().UTC(), } m := metrics.Metrics{ Config: config, } for _, fn := range root.Project.Functions { m.FunctionNames = append(m.FunctionNames, fn.FunctionName) } aggregated := m.Collect() fmt.Println() for _, fn := range root.Project.Functions { m := aggregated[fn.FunctionName] conf, err := service.GetFunctionConfiguration(&lambda.GetFunctionConfigurationInput{FunctionName: &fn.FunctionName}) if err != nil { return err } memory := int(*conf.MemorySize) costTotal := humanize.FormatFloat("", cost.Cost(m.Invocations, m.Duration, memory)) costDuration := humanize.FormatFloat("", cost.DurationCost(m.Duration, memory)) costInvocations := humanize.FormatFloat("", cost.RequestCost(m.Invocations)) fmt.Printf(" \033[%dm%s\033[0m\n", colors.Blue, fn.Name) fmt.Printf(" total cost: $%s\n", costTotal) fmt.Printf(" invocations: %s ($%s)\n", humanize.Comma(int64(m.Invocations)), costInvocations) fmt.Printf(" duration: %s ($%s)\n", time.Millisecond*time.Duration(m.Duration), costDuration) fmt.Printf(" throttles: %v\n", m.Throttles) fmt.Printf(" errors: %s\n", humanize.Comma(int64(m.Errors))) fmt.Printf(" memory: %d\n", memory) fmt.Println() } return nil }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Init", nil) if err := root.Prepare(c, args); err != nil { return err } region := root.Config.Region if region == nil { return errors.New("AWS region missing, are your credentials set up? Visit http://apex.run/#aws-credentials for more details") } return boot.All(*region) }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Invoke", map[string]interface{}{ "has_alias": alias != "", "has_logs": includeLogs, }) dec := json.NewDecoder(input()) root.Project.Alias = alias if err := root.Project.LoadFunctions(name); err != nil { return err } fn := root.Project.Functions[0] for { var v map[string]interface{} err := dec.Decode(&v) if err == io.EOF { break } if err != nil { return fmt.Errorf("parsing response: %s", err) } var reply, logs io.Reader if e, ok := v["event"].(map[string]interface{}); ok { reply, logs, err = fn.Invoke(e, v["context"]) } else { reply, logs, err = fn.Invoke(v, nil) } if includeLogs { io.Copy(os.Stderr, logs) } if err != nil { return fmt.Errorf("function response: %s", err) } io.Copy(os.Stdout, reply) fmt.Fprintf(os.Stdout, "\n") } return nil }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Deploy", map[string]interface{}{ "concurrency": concurrency, "has_alias": alias != "", "env": len(env), "args": len(args), }) root.Project.Concurrency = concurrency root.Project.Alias = alias c.Root().PersistentFlags().Lookup("name string") if err := root.Project.LoadFunctions(args...); err != nil { return err } for _, fn := range root.Project.Functions { stats.Track("Deploy Function", map[string]interface{}{ "runtime": fn.Runtime, "has_alias": alias != "", "env": len(env), }) } for _, s := range env { parts := strings.SplitN(s, "=", 2) if len(parts) == 2 { root.Project.Setenv(parts[0], parts[1]) } else { return fmt.Errorf("environment variable %s needs a value", parts[0]) } } return root.Project.DeployAndClean() }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("List", map[string]interface{}{ "tfvars": tfvars, }) if err := root.Project.LoadFunctions(); err != nil { return err } if tfvars { outputTFvars() } else { outputList() } return nil }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Rollback", map[string]interface{}{ "has_alias": alias != "", "has_version": version != "", }) root.Project.Alias = alias if err := root.Project.LoadFunctions(args...); err != nil { return err } if version == "" { return root.Project.Rollback() } return root.Project.RollbackVersion(version) }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Init", nil) if err := root.Prepare(c, args); err != nil { return err } region := root.Config.Region if region == nil { return errors.New(credentialsError) } b := boot.Bootstrapper{ IAM: iam.New(root.Session), Region: *region, } return b.Boot() }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Infra", nil) err := root.Project.LoadFunctions() // Hack to prevent initial `apex infra apply` from failing, // as we load functions to expose their ARNs. if err != nil { if !strings.Contains(err.Error(), "Role: zero value") { return err } } p := &infra.Proxy{ Functions: root.Project.Functions, Region: *root.Session.Config.Region, Environment: root.Project.Environment, } return p.Run(args...) }
// Run command. func run(c *cobra.Command, args []string) error { if err := root.Project.LoadFunctions(name); err != nil { return err } fn := root.Project.Functions[0] stats.Track("Build", map[string]interface{}{ "runtime": fn.Runtime, "env": len(env), "has_env_file": envFile != "", }) if envFile != "" { if err := root.Project.LoadEnvFromFile(envFile); err != nil { return fmt.Errorf("reading env file %q: %s", envFile, err) } } vars, err := utils.ParseEnv(env) if err != nil { return err } for k, v := range vars { root.Project.Setenv(k, v) } zip, err := fn.Build() if err != nil { return err } if err := fn.Clean(); err != nil { return err } _, err = io.Copy(os.Stdout, zip) return err }
// Run command. func run(c *cobra.Command, args []string) error { if err := root.Project.LoadFunctions(name); err != nil { return err } fn := root.Project.Functions[0] stats.Track("Build", map[string]interface{}{ "runtime": fn.Runtime, }) zip, err := fn.Build() if err != nil { return err } if err := fn.Clean(); err != nil { return err } _, err = io.Copy(os.Stdout, zip) return err }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Delete", map[string]interface{}{ "force": force, "args": len(args), }) if err := root.Project.LoadFunctions(args...); err != nil { return err } if !force && len(root.Project.Functions) > 1 { fmt.Printf("The following will be deleted:\n\n") for _, fn := range root.Project.Functions { fmt.Printf(" - %s\n", fn.Name) } fmt.Printf("\n") } if !force && !prompt.Confirm("Are you sure? (yes/no) ") { return nil } return root.Project.Delete() }
// Run command. func run(c *cobra.Command, args []string) error { stats.Track("Upgrade", nil) return upgrade.Upgrade(version.Version) }