https://pulumi.com logo
Title
t

tall-state-52885

11/09/2022, 11:24 PM
Hi folks, I have a problem using awsx.apigateway.API, where all POST requests have body base64 encoded. Clients are sending raw json body, with content-type=application/json. I read a post that suggested some versions of Pulumi cause that, but you can work around it with restApiArgs.binaryMediaTypes. But, that didn't work for me. I'm on the latest Pulumi v3.46.1. Has anyone got suggestions or ideas?
l

little-soccer-5693

11/10/2022, 12:49 AM
@tall-state-52885 i used aws.apigatewayv2 and not awsx.apigateway so YMMV but in my handler function i've seen both base64 and non-base64 encoded request.body which seems to be driven by clients and not api gateway itself. in my handler function i just optionally decode when the body is base64 encoded. e.g.:
func handler(ctx context.Context,
	request events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse,
	error) {

	var err error

	errorResponse := events.APIGatewayV2HTTPResponse{
		StatusCode:      500,
		Body:            "",
		IsBase64Encoded: false,
	}

	body := request.Body
	if request.IsBase64Encoded {
		decodedBody, err := base64.StdEncoding.DecodeString(request.Body)
		if err != nil {
			log.Printf("handler: Failed to base64 decode: %v", err)
			return errorResponse, err
		}
		body = string(decodedBody)
	}

        .....