Skip to content

Unable to remove environment variables from amplify App #2788

Closed
@jar-b

Description

Acknowledgements

Describe the bug

After creating an amplify app with environment variables configured, there is no way to remove them. The EnvironmentVariables field is a map[string]string and I've attempted the following.

  1. Set to map[string]string{}
  2. Set to nil
  3. Set to map[string]string{"": ""}

I'd expect either 1 or 2 to from above to remove the existing environment variables. 3 at one point worked with AWS SDK for Go V1 (see the Terraform AWS provider implementation and acceptance test), but even V1 now returns an error.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The ability to remove configured environment variables.

Current Behavior

Not possible to remove environment variables once configured.

Reproduction Steps

  1. Run the program below.
  2. Observe environment variables persisting in response output.
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/amplify"
)

func main() {
	ctx := context.TODO()
	cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("us-west-2"))
	if err != nil {
		log.Fatalf("unable to load SDK config, %v", err)
	}

	client := amplify.NewFromConfig(cfg)

	fmt.Println("Creating app...")
	out, err := client.CreateApp(ctx, &amplify.CreateAppInput{
		Name: aws.String("jb-test"),
		EnvironmentVariables: map[string]string{
			"foo": "bar",
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	appId := out.App.AppId

	fmt.Println("Attempt 1 -Updating to an empty map...")
	out1, err := client.UpdateApp(ctx, &amplify.UpdateAppInput{
		AppId:                appId,
		EnvironmentVariables: map[string]string{},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("result: %s\n", out1.App.EnvironmentVariables)

	fmt.Println("Attempt 2 - Updating to nil...")
	out2, err := client.UpdateApp(ctx, &amplify.UpdateAppInput{
		AppId:                appId,
		EnvironmentVariables: nil,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("result: %s\n", out2.App.EnvironmentVariables)

	fmt.Println("Attempt 3 - Updating to a map with an empty key/value pair...")
	_, err = client.UpdateApp(ctx, &amplify.UpdateAppInput{
		AppId:                appId,
		EnvironmentVariables: map[string]string{"": ""},
	})
	if err != nil {
		// This previously worked with AWS SDK for Go V1, but is now an error
		// Ref: https://github.com/hashicorp/terraform-provider-aws/blob/898c9b5a1d8958366b293dad02daa44e24e360ef/internal/service/amplify/app.go#L510-L516
		fmt.Println(err)
	}

	fmt.Println("Deleting app...")
	_, err = client.DeleteApp(ctx, &amplify.DeleteAppInput{
		AppId: appId,
	})
	if err != nil {
		log.Fatal(err)
	}
}

Result:

Creating app...
Attempt 1 -Updating to an empty map...
result: map[foo:bar]
Attempt 2 - Updating to nil...
result: map[foo:bar]
Attempt 3 - Updating to a map with an empty key/value pair...
operation error Amplify: UpdateApp, https response error StatusCode: 400, RequestID: 590409c6-6695-435b-ab03-b579db62576f, BadRequestException: Environment variables cannot have an empty key.
Deleting app...

Possible Solution

No response

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

module main

go 1.23.1

require (
	github.com/aws/aws-sdk-go-v2 v1.30.5
	github.com/aws/aws-sdk-go-v2/config v1.27.33
	github.com/aws/aws-sdk-go-v2/service/amplify v1.24.3
)

require (
	github.com/aws/aws-sdk-go-v2/credentials v1.17.32 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.13 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.4 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.22.7 // indirect
	github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.7 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.30.7 // indirect
	github.com/aws/smithy-go v1.20.4 // indirect
)

Compiler and Version used

go version go1.23.1 darwin/arm64

Operating System and version

MacOS Sonoma 14.6.1

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions