Hey folks, I’m creating an automation API in Go an...
# automation-api
g
Hey folks, I’m creating an automation API in Go and for testing local I’m using the LocalStack S3 bucket as a backend, but when I try to create a new stack I get this error:
Copy code
failed to create stack: exit status 255
code: 255
stdout: 
stderr: Logging in using access token from PULUMI_ACCESS_TOKEN
error: getting user info from <http://localhost:4566/project-gaia>: [404] <?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>NoSuchKey</Code>
    <Message>The specified key does not exist.</Message>
    <Key>api/user</Key>
    <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
</Error>
Ps: Using with
pulumi new
, it worked well
I logged using this command:
Copy code
  ~ ❯ pulumi login "<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>"                              ✘ INT  11:59:49
Logged in to xpto as romulofranca (<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>)
and using
pulumi new
:
b
hi, we talked about this the other day. Please show the output of
pulumi whoami
- you need to login to a backend first
g
Hi @billowy-army-68599 I logged, see the message:
Copy code
Logged in to xpto as romulofranca (<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>)
After we talk, I identify the problem, missing quotes in endpoint url
and after a lot of trying I just found the problem, in the api function I needed to pass the same url that I passed in pulumi login
Copy code
func CreateHandler(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	var createReq CreatePolicyReq
	err := json.NewDecoder(req.Body).Decode(&createReq)
	if err != nil {
		w.WriteHeader(400)
		fmt.Fprintf(w, "failed to parse create request")
		return
	}

	ctx := context.Background()

	stackName := createReq.Name
	program := services.CreateStack("gaia-test-policy", "gaia-test-role")

	opts := []auto.LocalWorkspaceOption{
		auto.Project(workspace.Project{
			Name:    tokens.PackageName(stackName),
			Runtime: workspace.NewProjectRuntimeInfo("go", nil),
			Backend: &workspace.ProjectBackend{
				URL: "<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>",
			},
		}),
	}

	s, err := auto.UpsertStackInlineSource(ctx, stackName, stackName, program, opts...)
	//s, err := auto.NewStackInlineSource(ctx, stackName, stackName, program)
	if err != nil {

		if auto.IsCreateStack409Error(err) {
			w.WriteHeader(409)
			fmt.Fprintf(w, fmt.Sprintf("stack %q already exists", stackName))
			return
		}

		w.WriteHeader(500)
		fmt.Fprintf(w, err.Error())
		return
	}
	s.SetConfig(ctx, "aws:region", auto.ConfigValue{Value: "eu-west-1"})

	upRes, err := s.Up(ctx, optup.ProgressStreams(os.Stdout))
	if err != nil {
		w.WriteHeader(500)
		fmt.Fprintf(w, err.Error())
		return
	}

	response := &PolicyResponse{
		Name:      stackName,
		PolicyArn: upRes.Outputs["policyArn"].Value.(string),
		RoleArn:   upRes.Outputs["roleArn"].Value.(string),
	}
	err = json.NewEncoder(w).Encode(&response)
	if err != nil {
		return
	}
}
if anyone is interested☝️