Skip to content

Commit 0dcc18a

Browse files
committed
Improve GetAWSContainer error handling
1 parent a2b6121 commit 0dcc18a

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ To see which config file is currently in use:
8383
lstk config path
8484
```
8585

86+
You can also configure AWS CLI integration:
87+
88+
```bash
89+
lstk setup aws
90+
```
91+
92+
This sets up a `localstack` profile in `~/.aws/config` and `~/.aws/credentials`.
93+
8694
You can also point `lstk` at a specific config file for any command:
8795

8896
```bash
@@ -184,6 +192,9 @@ lstk update
184192
# Show resolved config file path
185193
lstk config path
186194

195+
# Set up AWS CLI profile integration
196+
lstk setup aws
197+
187198
```
188199

189200
## Reporting bugs

internal/config/containers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ func (c *ContainerConfig) ProductName() (string, error) {
140140
}
141141

142142
// GetAWSContainer returns the AWS container config from the list of containers.
143-
// Returns nil if no AWS container is configured.
144-
func GetAWSContainer(containers []ContainerConfig) *ContainerConfig {
143+
// Returns an error if no AWS container is configured.
144+
func GetAWSContainer(containers []ContainerConfig) (*ContainerConfig, error) {
145145
for i := range containers {
146146
if containers[i].Type == EmulatorAWS {
147-
return &containers[i]
147+
return &containers[i], nil
148148
}
149149
}
150-
return nil
150+
return nil, fmt.Errorf("no aws emulator configured")
151151
}

internal/ui/run_awsconfig.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ui
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/localstack/lstk/internal/awsconfig"
87
"github.com/localstack/lstk/internal/config"
@@ -13,9 +12,9 @@ import (
1312
// RunConfigProfile runs the AWS profile setup flow with TUI output.
1413
// It resolves the host from the AWS container config and runs the setup.
1514
func RunConfigProfile(parentCtx context.Context, containers []config.ContainerConfig, localStackHost string) error {
16-
awsContainer := config.GetAWSContainer(containers)
17-
if awsContainer == nil {
18-
return fmt.Errorf("no aws emulator configured")
15+
awsContainer, err := config.GetAWSContainer(containers)
16+
if err != nil {
17+
return err
1918
}
2019

2120
resolvedHost, dnsOK := endpoint.ResolveHost(awsContainer.Port, localStackHost)

test/integration/awsconfig_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func TestStartSkipsAWSProfilePromptWhenAlreadyConfigured(t *testing.T) {
134134
_ = cmd.Process.Kill()
135135
err = cmd.Wait()
136136
<-outputCh
137-
require.NoError(t, err, "lstk start should exit after kill")
137+
// Process was killed, so we expect an error from Wait()
138+
require.Error(t, err, "lstk start should exit after kill")
138139

139140
assert.NotContains(t, out.String(), awsSetupPrompt,
140141
"profile prompt should not appear when profile is already correctly configured")

0 commit comments

Comments
 (0)