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

SDK UpdateChannel Call Fails to Update IVS Channel Type #2262

Closed
jaasco opened this issue Sep 1, 2023 · 2 comments
Closed

SDK UpdateChannel Call Fails to Update IVS Channel Type #2262

jaasco opened this issue Sep 1, 2023 · 2 comments
Assignees
Labels
bug This issue is a bug.

Comments

@jaasco
Copy link

jaasco commented Sep 1, 2023

Describe the bug

When attempting to update the IVS channel's type from "Advanced HD" to "Standard" using the SDK, a ValidationException error is encountered. The SDK call seems to be not compatible with the desired preset and channel type combination.
Upon making the SDK call to change the channel type, instead of the channel type updating as expected, an error message is returned indicating a mismatch between the preset HIGHER_BANDWIDTH_DELIVERY and the desired channel type STANDARD.

Expected Behavior

The IVS channel's type should successfully update from "Advanced HD" to "Standard" without any errors. After making the SDK call, the channel type should reflect the new value "Standard" in the system.

Current Behavior

Upon attempting to update the IVS channel's type from "Advanced HD" to "Standard" using the SDK, the system returns a ValidationException error. The error message suggests a mismatch: preset: HIGHER_BANDWIDTH_DELIVERY not match channel type: STANDARD. The channel type remains unchanged post the call.

Reproduction Steps

  1. Ensure you have an IVS channel set with the Channel type "Advanced HD".
  2. Utilize the SDK to make a call with the following code snippet:
    channelType := ivstypes.ChannelTypeStandardChannelType
    preset := ""
    _, err = awsclient.Ivs.UpdateChannel(ctx, &ivs.UpdateChannelInput{
        Arn:    &channelId,
        Preset: preset,
        Type:   channelType,
    }, awsclient.IvsCredFunc(*channel.Region, *channel.RoleArn))
  3. Observe the returned error message and verify that the channel type has not been updated in the system.

Possible Solution

It appears the issue might stem from the fact that in Go, an empty string might not be transmitted in the HTTP request. The omitempty directive might be set in the struct tag for the related field, causing it to be omitted from the request when it's empty.

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go-v2/service/ivs@v1.26.0 github.com/aws/aws-sdk-go-v2@v1.21.0
github.com/aws/aws-sdk-go-v2/service/ivs@v1.26.0 github.com/aws/aws-sdk-go-v2/internal/configsources@v1.1.41
github.com/aws/aws-sdk-go-v2/service/ivs@v1.26.0 github.com/aws/aws-sdk-go-v2/internal/endpoints/v2@v2.4.35
github.com/aws/aws-sdk-go-v2/service/ivs@v1.26.0 github.com/aws/smithy-go@v1.14.2
github.com/aws/aws-sdk-go-v2/service/ivs@v1.26.0 github.com/google/go-cmp@v0.5.8

Compiler and Version used

go version go1.19.3 darwin/amd64

Operating System and version

Amazon Linux

@jaasco jaasco added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 1, 2023
@RanVaknin RanVaknin self-assigned this Sep 1, 2023
@RanVaknin
Copy link
Contributor

RanVaknin commented Sep 1, 2023

Hi @jaasco,

Thanks for the bug report. This is related to this issue we are having with the lack of default value serialization.

You can get around it with adding a middleware to manually edit the body before its signed:

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/ivs"
	"github.com/aws/aws-sdk-go-v2/service/ivs/types"
	"github.com/aws/smithy-go/middleware"
	smithyhttp "github.com/aws/smithy-go/transport/http"
	"io"
	"log"
	"strings"
)

func main() {
	cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"), config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponseWithBody))
	if err != nil {
		log.Fatalf("unable to load SDK config, %v", err)
	}

	if err != nil {
		fmt.Println("Error creating session:", err)
		return
	}
	myMiddleware := middleware.SerializeMiddlewareFunc("MyTestMiddleware",
		func(ctx context.Context, input middleware.SerializeInput, next middleware.SerializeHandler,
		) (
			output middleware.SerializeOutput, metadata middleware.Metadata, err error,
		) {
			req, ok := input.Request.(*smithyhttp.Request)
			if !ok {
				return output, metadata, fmt.Errorf("unexpected transport: %T", input.Request)
			}

			bodyStream := req.GetStream()
			buf := new(strings.Builder)
			_, err = io.Copy(buf, bodyStream)
			actualBodyString := buf.String()

			substring := `{"`
			index := strings.Index(actualBodyString, substring)

			newBodyString := actualBodyString[:index+len(substring)] + `preset":"","` + actualBodyString[len(substring)+index:]
			newStream := strings.NewReader(newBodyString)

			req.ContentLength = int64(len(newBodyString))
			input.Request = req

			input.Request, err = req.SetStream(newStream)
			if err != nil {
				panic(err)
			}

			return next.HandleSerialize(ctx, input)
		})
	client := ivs.NewFromConfig(cfg)

	out, err := client.CreateChannel(context.TODO(), &ivs.CreateChannelInput{
		Name: aws.String("foo-channel2"),
		Type: types.ChannelTypeAdvancedHDChannelType,
	})
	if err != nil {
		panic(err)
	}

	channelArn := out.Channel.Arn

	_, err = client.UpdateChannel(context.TODO(), &ivs.UpdateChannelInput{
		Arn:    channelArn,
		Preset: "",
		Type:   types.ChannelTypeStandardChannelType,
	}, func(options *ivs.Options) {
		options.APIOptions = append(options.APIOptions, func(stack *middleware.Stack) error {
			return stack.Serialize.Add(myMiddleware, middleware.After)
		})
	})

	if err != nil {
		panic(err)
	}
}

At this point there is no straightforward way to fix this.

Thanks,
Ran~

@RanVaknin RanVaknin closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
@github-actions
Copy link

github-actions bot commented Sep 1, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@RanVaknin RanVaknin removed the needs-triage This issue or PR still needs to be triaged. label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants