Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to remove environment variables from amplify App #2788

Closed
2 of 3 tasks
jar-b opened this issue Sep 13, 2024 · 3 comments
Closed
2 of 3 tasks

Unable to remove environment variables from amplify App #2788

jar-b opened this issue Sep 13, 2024 · 3 comments
Assignees

Comments

@jar-b
Copy link

jar-b commented Sep 13, 2024

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

@jar-b jar-b added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 13, 2024
@bhavya2109sharma bhavya2109sharma self-assigned this Sep 17, 2024
@bhavya2109sharma bhavya2109sharma removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 18, 2024
@bhavya2109sharma
Copy link
Contributor

Hello @jar-b,

Thanks for reaching out.

To delete the environment variables, you need to set the key to a space character and the value to an empty string.
Here is the code that will delete the environment variables:

fmt.Println("Deleting environment variables...")
	out1, err := client.UpdateApp(ctx, &amplify.UpdateAppInput{
		AppId: aws.String(appId),
		EnvironmentVariables: map[string]string{
			" ": "",
		},
	})

Thanks
~Bhavya

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@jar-b
Copy link
Author

jar-b commented Sep 19, 2024

Thank you for the clarification @bhavya2109sharma!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants