aws-sdk-go-v2 icon indicating copy to clipboard operation
aws-sdk-go-v2 copied to clipboard

Cognito AdminCreateUser, AdminDeleteUser, AdminDisableUser returning tcp no such host error

Open jasonkofo opened this issue 3 years ago • 2 comments

Describe the bug

All calls into the cognito identity provider are falling with no such host TCP errors. Running the individual commands from the AWS cli produces the correct results, however, calls from the SDK do not work.

Expected Behavior

I expect to be able to progress with cognito operations.

Current Behavior

operation error Cognito Identity Provider: AdminDisableUser, exceeded maximum number of attempts, 3, https response error StatusCode: 0, RequestID: , request send failed, Post \"https://cognito-idp.eu-west-1_XrdhhKGBb.amazonaws.com/\": dial tcp: lookup cognito-idp.eu-west-1_xxxxxxxxx.amazonaws.com: no such host

Reproduction Steps

func (x *pfCognitoClientPoolManagerV2) createCognitoUser(ctx context.Context, user RemoteUser) error {
	attrs := make([]cognitotypes.AttributeType, 0, 2)
	media := make([]cognitotypes.DeliveryMediumType, 0, 2)

	attrs = append(attrs, cognitotypes.AttributeType{Name: utils.String("email"), Value: user.Email})
	media = append(media, "EMAIL")
	if user.Mobile != nil {
		attrs = append(attrs, cognitotypes.AttributeType{Name: utils.String("phone_number"), Value: user.Mobile})
		media = append(media, "SMS")
	}

	createuserinput := &cognito.AdminCreateUserInput{
		UserPoolId:     &(*x).userPoolId,
		Username:       user.Username,
		UserAttributes: attrs,
		MessageAction:  "SUPPRESS",
	}
	_, err := x.provider.AdminCreateUser(ctx, createuserinput)
	if err != nil {
		return fmt.Errorf("could not create cognito user: %v", err.Error())
	}
	return nil
}

Possible Solution

No response

Additional Information/Context

I am calling this API from my personal machine, which produces the same issues as what was seen from AWS lambdas

Current location: Stellenbosch, Cape Town, South Africa Cognito Region: eu-west-1

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go-v2 v1.16.15 // indirect
github.com/aws/aws-sdk-go-v2/config v1.17.6
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.20.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.17.0
github.com/aws/aws-sdk-go-v2/service/sns v1.18.0
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.15.22
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.4 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.19 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.16 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.16 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.22 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.18 // indirect

Compiler and Version used

go version go1.18 linux/amd64

Operating System and version

Ubuntu 22.04 LTS

jasonkofo avatar Sep 16 '22 15:09 jasonkofo

@jasonkofo

Thanks for opening this issue,

I'm not sure why you are running into this error but my guess would be that your client is not set up correctly. Its hard to know because you seem to be wrapping it with pfCognitoClientPoolManagerV2 struct and I'm not sure what your provider field looks like since that part is missing.

Also I have noticed you are using createuserinput := &cognito.AdminCreateUserInput{ Are you prefixing your import as cognito? because it is supposed to be createuserinput := &cognitoidentityprovider.AdminCreateUserInput{

Here is my working code:

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/cognitoidentityprovider"
	"log"
)

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

	client := cognitoidentityprovider.NewFromConfig(cfg)

	createuserinput := &cognitoidentityprovider.AdminCreateUserInput{
		UserPoolId:    aws.String("userPoolID"),
		Username:      aws.String("Oscar"),
		MessageAction: "SUPPRESS",
	}
	res, err := client.AdminCreateUser(context.Background(), createuserinput)
	if err != nil {
		fmt.Errorf("could not create cognito user: %v", err.Error())
	}

	fmt.Println(*res.User.Username)
}

outputs: oscar

Let me know if that helps. Thanks, Ran

RanVaknin avatar Sep 28 '22 22:09 RanVaknin

This issue has not received a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

github-actions[bot] avatar Oct 01 '22 00:10 github-actions[bot]