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

Amplify v2 increases Auth.signin() time by 3x #3007

Closed
sebsto opened this issue Jun 6, 2023 · 15 comments
Closed

Amplify v2 increases Auth.signin() time by 3x #3007

sebsto opened this issue Jun 6, 2023 · 15 comments
Assignees
Labels
auth Issues related to the Auth category bug Something isn't working

Comments

@sebsto
Copy link

sebsto commented Jun 6, 2023

Describe the bug

We have recently migrated to using AWS Amplify SDK for iOS v2.11 and have observed that ~3/10 sign-in operation take significant time to complete (5-10 sec). This was not happening when we were using AWS Amplify SDK v.1.27. The slow response time is related to following API call: https://docs.amplify.aws/lib/auth/signin/q/platform/ios/#sign-in-a-user.

It sometimes “hangs” for 5-10 seconds before completing. We have tried looking into network calls via Proxyman app but we’ve found that the Cognito call are not visible there when using Amplify SDK v2 (eg. As opposed to v1 or other call like AppSync). We have not been able to reproduce the issue when using AWS CLI commands (cognito-idp) - it takes ~1-2 sec to get response.

We have seen similar reports for Amplify framework on other platforms as well, eg: aws-amplify/amplify-js#5539

I am attaching log files and amplifyconfiguration.json files for the few tests I did. Please also see my observations below:

I compared sign-in times when using Amplify SDK v2.11.5 and v1.29.0 in our app and results are as follow:

What is more, for a application configuration where we use Amplify SDK v1 there is additional Lambda function configured as a PostSignin trigger in Cognito UserPool. Even with this Lambda signin operation only takes ~1-2s when using v1 SDK as compared to 5-6s when using Amplify SDK v2 with no Lambda.

Steps To Reproduce

Can not reproduce on a clean (new) app created with Amplify v2

Expected behavior

Signin time latency should not increase when migrating an app from Amplify v1 to v2

Amplify Framework Version

2.11.5

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5.7

CLI version

12.0.0

Xcode version

14.3.1

Relevant log output

Amplify v1 (OK) logs
2023-06-06 11:29:57:519 Evie Beta[987:263140] Request headers:
{
    "Content-Type" = "application/x-amz-json-1.1";
    Host = "cognito-idp.us-west-2.amazonaws.com";
    "User-Agent" = "amplify-iOS/1.29.0 iOS/16.3 en_PL";
    "X-Amz-Date" = 20230606T092957Z;
    "X-Amz-Target" = "AWSCognitoIdentityProviderService.InitiateAuth";
}
2023-06-06 11:29:57:519 Evie Beta[987:263140] Request body:
{"UserContextData":{"EncodedData":"<redacted>"},"ClientMetadata":{"cognito:deviceName":"iPhone","cognito:bundleShortV":"1.0","cognito:idForVendor":"26815F54-49A2-46E6-8BFE-331D269DE9AE","cognito:bundleVersion":"1","cognito:bundleId":"com.movano.ios.debug","cognito:model":"iPhone","cognito:systemName":"iOS","cognito:iOSVersion":"16.3"},"AuthParameters":{"SRP_A":"<redacted>","SECRET_HASH":"<redacted>","USERNAME":"<redacted>"},"AuthFlow":"USER_SRP_AUTH","ClientId":"<redacted>"}
2023-06-06 11:29:57:860 Evie Beta[987:262638] Response headers:
{
    "Content-Length" = 2731;
    "Content-Type" = "application/x-amz-json-1.1";
    Date = "Tue, 06 Jun 2023 09:29:57 GMT";
    "x-amzn-requestid" = "a6e65c8f-5acd-4038-b044-631fad7b1069";
}
2023-06-06 11:29:57:860 Evie Beta[987:262638] Response body:
{"ChallengeName":"PASSWORD_VERIFIER","ChallengeParameters":{"SALT":"<redacted>"}}
2023-06-06 11:29:57:918 Evie Beta[987:262638] Request headers:
{
    "Content-Type" = "application/x-amz-json-1.1";
    Host = "cognito-idp.us-west-2.amazonaws.com";
    "User-Agent" = "amplify-iOS/1.29.0 iOS/16.3 en_PL";
    "X-Amz-Date" = 20230606T092957Z;
    "X-Amz-Target" = "AWSCognitoIdentityProviderService.RespondToAuthChallenge";
}
2023-06-06 11:29:57:918 Evie Beta[987:262638] Request body:
{"UserContextData":{"EncodedData":"<redacted>"},"ChallengeResponses":{"PASSWORD_CLAIM_SECRET_BLOCK":"<redacted>","USERNAME":"<redacted>","SECRET_HASH":"<redacted>","PASSWORD_CLAIM_SIGNATURE":"<redacted>","TIMESTAMP":"Tue Jun 6 09:29:57 UTC 2023"},"ClientMetadata":{},"ChallengeName":"PASSWORD_VERIFIER","ClientId":"<redacted>"}
2023-06-06 11:29:58:375 Evie Beta[987:263140] Response headers:
{
    "Content-Length" = 4218;
    "Content-Type" = "application/x-amz-json-1.1";
    Date = "Tue, 06 Jun 2023 09:29:58 GMT";
    "x-amzn-requestid" = "f20f2450-4b3f-43e7-a41e-b45cef199c81";
}
2023-06-06 11:29:58:375 Evie Beta[987:263140] Response body:
{"AuthenticationResult":{"AccessToken":"<redacted>","ExpiresIn":3600,"IdToken":"<redacted>","RefreshToken":"<redacted>","TokenType":"Bearer"},"ChallengeParameters":{}}
2023-06-06 11:29:58.425859+0200 Evie Beta[987:263140] [Amplify] AWSMobileClient Event listener - signedIn
2023-06-06 11:29:58.426795+0200 Evie Beta[987:263010] [fzy] - signing duration: 0.9446649551391602
Amplify v2 (NOT OK) logs
2023-06-06 10:30:17.999068+0200 Evie Beta[931:244237] [AWSCognitoAuthPlugin] No existing device metadata found. AuthEnvironment(configuration: AWSCognitoAuthPlugin.AuthConfiguration.userPoolsAndIdentityPools(["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"oauth\": \"[\\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\", \"clientSecret\": \"(nil)\"]", "endpoint": "N/A"], ["region": "<REDACTED>", "poolId": "us-w****d529"]), userPoolConfigData: Optional(["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"oauth\": \"[\\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\", \"clientSecret\": \"(nil)\"]", "endpoint": "N/A"]), identityPoolConfigData: Optional(["region": "<REDACTED>", "poolId": "us-w****d529"]), authenticationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthenticationEnvironment(srpSignInEnvironment: AWSCognitoAuthPlugin.BasicSRPSignInEnvironment(srpAuthEnvironment: AWSCognitoAuthPlugin.BasicSRPAuthEnvironment(userPoolConfiguration: ["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\"]", "endpoint": "N/A"], cognitoUserPoolFactory: (Function), eventIDFactory: (Function), srpClientFactory: (Function), srpConfiguration: (nHexValue: "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF", gHexValue: "2"))), userPoolEnvironment: AWSCognitoAuthPlugin.BasicUserPoolEnvironment(userPoolConfiguration: ["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"oauth\": \"[\\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\", \"clientSecret\": \"(nil)\"]", "endpoint": "N/A"], cognitoUserPoolFactory: (Function), cognitoUserPoolASFFactory: (Function), cognitoUserPoolAnalyticsHandlerFactory: (Function)), hostedUIEnvironment: Optional(AWSCognitoAuthPlugin.BasicHostedUIEnvironment(configuration: ["oauth": "[\"signOutRedirectURI\": \"mova****p://\", \"signInRedirectURI\": \"mova****p://\", \"domain\": \"auth****loud\"]", "clientId": "6kjq****6ig8", "clientSecret": "(nil)"], hostedUISessionFactory: (Function), urlSessionFactory: (Function), randomStringFactory: (Function))))), authorizationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthorizationEnvironment(identityPoolConfiguration: ["region": "<REDACTED>", "poolId": "us-w****d529"], cognitoIdentityFactory: (Function), eventIDFactory: (Function))), credentialsClient: AWSCognitoAuthPlugin.CredentialStoreOperationClient, logger: DataStoreInfra.LoggingSpyPlugin.(unknown context at $10591ab10).LoggerDecorator)
2023-06-06T10:30:18+0200 info CognitoIdentityProviderClient : [Logging] Request: POST https:443
 Path: /
 Content-Length: 6639,
X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth,
Content-Type: application/x-amz-json-1.1,
Host: cognito-idp.us-west-2.amazonaws.com,
x-amz-user-agent: aws-sdk-swift/1.0,
User-Agent: aws-sdk-swift/1.0 api/cognito-identity-provider/1.0 os/iOS/16.3.0 lang/swift/5.7 lib/amplify-swift/2.11.5
 Optional([])
2023-06-06T10:30:18+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-idp.us-west-2.amazonaws.com/?")with max connections: 50
[Instabug] - IBGUser Steps: Captured screenshot using currentImageContext = <UIImage:0x281c00c60 anonymous {375, 667} renderingMode=automatic(original)>
2023-06-06T10:30:19+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/?")
2023-06-06 10:30:19.859827+0200 Evie Beta[931:244237] [AWSCognitoAuthPlugin] No existing device metadata found. AuthEnvironment(configuration: AWSCognitoAuthPlugin.AuthConfiguration.userPoolsAndIdentityPools(["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\"]", "endpoint": "N/A"], ["region": "<REDACTED>", "poolId": "us-w****d529"]), userPoolConfigData: Optional(["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"clientSecret\": \"(nil)\", \"clientId\": \"6kjq****6ig8\", \"oauth\": \"[\\\"domain\\\": \\\"auth****loud\\\", \\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\"]\"]", "endpoint": "N/A"]), identityPoolConfigData: Optional(["region": "<REDACTED>", "poolId": "us-w****d529"]), authenticationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthenticationEnvironment(srpSignInEnvironment: AWSCognitoAuthPlugin.BasicSRPSignInEnvironment(srpAuthEnvironment: AWSCognitoAuthPlugin.BasicSRPAuthEnvironment(userPoolConfiguration: ["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\"]", "endpoint": "N/A"], cognitoUserPoolFactory: (Function), eventIDFactory: (Function), srpClientFactory: (Function), srpConfiguration: (nHexValue: "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF", gHexValue: "2"))), userPoolEnvironment: AWSCognitoAuthPlugin.BasicUserPoolEnvironment(userPoolConfiguration: ["region": "<REDACTED>", "clientId": "6kjq****6ig8", "poolId": "us-w****Fn3g", "clientSecret": "(nil)", "pinpointAppId": "(nil)", "hostedUI": "[\"clientSecret\": \"(nil)\", \"oauth\": \"[\\\"signOutRedirectURI\\\": \\\"mova****p://\\\", \\\"signInRedirectURI\\\": \\\"mova****p://\\\", \\\"domain\\\": \\\"auth****loud\\\"]\", \"clientId\": \"6kjq****6ig8\"]", "endpoint": "N/A"], cognitoUserPoolFactory: (Function), cognitoUserPoolASFFactory: (Function), cognitoUserPoolAnalyticsHandlerFactory: (Function)), hostedUIEnvironment: Optional(AWSCognitoAuthPlugin.BasicHostedUIEnvironment(configuration: ["clientId": "6kjq****6ig8", "clientSecret": "(nil)", "oauth": "[\"domain\": \"auth****loud\", \"signInRedirectURI\": \"mova****p://\", \"signOutRedirectURI\": \"mova****p://\"]"], hostedUISessionFactory: (Function), urlSessionFactory: (Function), randomStringFactory: (Function))))), authorizationEnvironment: Optional(AWSCognitoAuthPlugin.BasicAuthorizationEnvironment(identityPoolConfiguration: ["region": "<REDACTED>", "poolId": "us-w****d529"], cognitoIdentityFactory: (Function), eventIDFactory: (Function))), credentialsClient: AWSCognitoAuthPlugin.CredentialStoreOperationClient, logger: DataStoreInfra.LoggingSpyPlugin.(unknown context at $10591ab10).LoggerDecorator)
2023-06-06T10:30:19+0200 info CognitoIdentityProviderClient : [Logging] Request: POST https:443
 Path: /
 Host: cognito-idp.us-west-2.amazonaws.com,
User-Agent: aws-sdk-swift/1.0 api/cognito-identity-provider/1.0 os/iOS/16.3.0 lang/swift/5.7 lib/amplify-swift/2.11.5,
Content-Length: 7800,
Content-Type: application/x-amz-json-1.1,
X-Amz-Target: AWSCognitoIdentityProviderService.RespondToAuthChallenge,
x-amz-user-agent: aws-sdk-swift/1.0
 Optional([])
2023-06-06T10:30:19+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-idp.us-west-2.amazonaws.com/?")with max connections: 50
2023-06-06T10:30:21+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/?")
[Instabug] - IBGUser Steps: Captured screenshot using currentImageContext = <UIImage:0x281c00c60 anonymous {375, 667} renderingMode=automatic(original)>
2023-06-06T10:30:21+0200 info CognitoIdentityClient : [Logging] Request: POST https:443
 Path: /
 x-amz-user-agent: aws-sdk-swift/1.0,
X-Amz-Target: AWSCognitoIdentityService.GetId,
Content-Length: 1357,
Content-Type: application/x-amz-json-1.1,
User-Agent: aws-sdk-swift/1.0 api/cognito-identity/1.0 os/iOS/16.3.0 lang/swift/5.7 lib/amplify-swift/2.11.5,
Host: cognito-identity.us-west-2.amazonaws.com
 Optional([])
2023-06-06T10:30:21+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-identity.us-west-2.amazonaws.com/?")with max connections: 50
2023-06-06T10:30:23+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/?")
2023-06-06T10:30:23+0200 info CognitoIdentityClient : [Logging] Request: POST https:443
 Path: /
 x-amz-user-agent: aws-sdk-swift/1.0,
Content-Length: 1353,
Content-Type: application/x-amz-json-1.1,
X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity,
User-Agent: aws-sdk-swift/1.0 api/cognito-identity/1.0 os/iOS/16.3.0 lang/swift/5.7 lib/amplify-swift/2.11.5,
Host: cognito-identity.us-west-2.amazonaws.com
 Optional([])
2023-06-06T10:30:23+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-identity.us-west-2.amazonaws.com/?")with max connections: 50
[Instabug] - IBGUser Steps: Captured screenshot using currentImageContext = <UIImage:0x281c00cf0 anonymous {375, 667} renderingMode=automatic(original)>
2023-06-06T10:30:23+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/?")
2023-06-06 10:30:24.192135+0200 Evie Beta[931:244258] User is signed in!
2023-06-06 10:30:24.193132+0200 Evie Beta[931:244269] [fzy] - signing duration: 6.229087542 seconds

Is this a regression?

Yes

Regression additional context

No response

Device

all

iOS Version

multiple

Specific to simulators

no

Additional context

No response

@sebsto
Copy link
Author

sebsto commented Jun 6, 2023

Amplify v1 configuration
{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "IdentityManager": {
                    "Default": {}
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-west-2_aEXGnKFRT",
                        "AppClientId": "65hdf3qt7ptbl55udk3mp6ilv5",
                        "AppClientSecret": "<redacted>",
                        "Region": "us-west-2"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "OAuth": {
                            "WebDomain": "intent-auth.movano.cloud",
                            "AppClientId": "65hdf3qt7ptbl55udk3mp6ilv5",
                            "AppClientSecret": "<redacted>",
                            "SignInRedirectURI": "movanoapp://",
                            "SignOutRedirectURI": "movanoapp://",
                            "Scopes": [
                                "phone",
                                "email",
                                "openid",
                                "profile",
                                "aws.cognito.signin.user.admin"
                            ]
                        }
                    }
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "https://3y7oxixoendsraee4flafesuha.appsync-api.us-west-2.amazonaws.com/graphql",
                        "Region": "us-west-2",
                        "AuthMode": "AMAZON_COGNITO_USER_POOLS",
                        "ClientDatabasePrefix": "INTENT-DEV_AMAZON_COGNITO_USER_POOLS"
                    }
                }
            }
        }
    },
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "INTENT-DEV": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://3y7oxixoendsraee4flafesuha.appsync-api.us-west-2.amazonaws.com/graphql",
                    "region": "us-west-2",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                },
                "REST_API": {
                    "endpointType": "REST",
                    "endpoint": "https://ejykq2mu74.execute-api.us-west-2.amazonaws.com/INTENT-DEV",
                    "region": "us-west-2",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                }
            }
        }
    }
}

Amplify v2 configuration
{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "RingAppApi": {
                    "endpointType": "REST",
                    "endpoint": "https://90hsa9ir13.execute-api.us-west-2.amazonaws.com/intentd",
                    "region": "us-west-2",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                },
                "ringapp": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://76gowagcazevheefrg4cwxdcom.appsync-api.us-west-2.amazonaws.com/graphql",
                    "region": "us-west-2",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS",
                    "apiKey": "<removed>"
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify/cli",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "https://76gowagcazevheefrg4cwxdcom.appsync-api.us-west-2.amazonaws.com/graphql",
                        "Region": "us-west-2",
                        "AuthMode": "AMAZON_COGNITO_USER_POOLS",
                        "ClientDatabasePrefix": "ringapp_AMAZON_COGNITO_USER_POOLS"
                    },
                    "ringapp_API_KEY": {
                        "ApiUrl": "https://76gowagcazevheefrg4cwxdcom.appsync-api.us-west-2.amazonaws.com/graphql",
                        "Region": "us-west-2",
                        "AuthMode": "API_KEY",
                        "ApiKey": "<removed>",
                        "ClientDatabasePrefix": "ringapp_API_KEY"
                    }
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-west-2:362c3f3b-e385-4874-b490-5c207dd1d529",
                            "Region": "us-west-2"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-west-2_o0zEgFn3g",
                        "AppClientId": "6kjqvc7svub6cq9k0altiv6ig8",
                        "Region": "us-west-2"
                    }
                },
                "Auth": {
                    "Default": {
                        "OAuth": {
                            "WebDomain": "auth2.intent.movano.cloud",
                            "AppClientId": "6kjqvc7svub6cq9k0altiv6ig8",
                            "SignInRedirectURI": "movanoapp://",
                            "SignOutRedirectURI": "movanoapp://",
                            "Scopes": [
                                "phone",
                                "email",
                                "openid",
                                "profile",
                                "aws.cognito.signin.user.admin"
                            ]
                        },
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "socialProviders": [
                            "GOOGLE",
                            "APPLE"
                        ],
                        "usernameAttributes": [
                            "EMAIL"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                },
                "DynamoDBObjectMapper": {
                    "Default": {
                        "Region": "us-west-2"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "apps3storage83114-intentd",
                        "Region": "us-west-2"
                    }
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsDynamoDbStoragePlugin": {
                "partitionKeyName": "user_id",
                "sortKeyName": "job_id",
                "sortKeyType": "S",
                "region": "us-west-2",
                "arn": "arn:aws:dynamodb:us-west-2:676488953296:table/SleepServiceV2-intentd",
                "streamArn": "arn:aws:dynamodb:us-west-2:676488953296:table/SleepServiceV2-intentd/stream/2023-04-15T00:39:39.073",
                "partitionKeyType": "S",
                "name": "SleepServiceV2-intentd"
            },
            "awsS3StoragePlugin": {
                "bucket": "apps3storage83114-intentd",
                "region": "us-west-2",
                "defaultAccessLevel": "guest"
            }
        }
    }
}

@harsh62 harsh62 self-assigned this Jun 8, 2023
@harsh62 harsh62 added auth Issues related to the Auth category p2 and removed p2 labels Jun 8, 2023
@jbelkins
Copy link

@sebsto @harsh62 I've been trying to reproduce this issue in the AWS SDK for Swift but can't reproduce the type of delays you are reporting.

I note that it says above that you tried to reproduce in a clean / new project but couldn't.

Do you have a code sample or some other way to attempt to recreate the issue?

@fzy-github
Copy link

@jbelkins The code we use in the project is exactly the same as in the official documentation here: https://docs.amplify.aws/lib/auth/signin/q/platform/ios/#sign-in-a-user

I am not sure about the clean project as we only tried on different Amplify SDK versions - I will try to set up new amplify project and replicate it there.

@phantumcode phantumcode added the bug Something isn't working label Jul 24, 2023
@fzy-github
Copy link

fzy-github commented Jul 28, 2023

@jbelkins I have created a sample project to demonstrate the issue. You can find it here:

https://github.com/fzy-spyro/AmplifySlowSignin

on "main" branch I am using amplify 2.15.1 where signin usually takes > 3 seconds. Logs from the execution are eg:

⏰ signIn() clicked!
2023-07-28T13:58:42+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/?")
2023-07-28T13:58:42+0200 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 Content-Length: 1225, 
Content-Type: application/x-amz-json-1.1, 
x-amz-user-agent: aws-sdk-swift/1.0, 
Host: cognito-identity.us-west-2.amazonaws.com, 
User-Agent: aws-sdk-swift/1.0 api/cognito-identity/1.0 os/iOS/16.4.0 lang/swift/5.8 lib/amplify-swift/2.12.0, 
X-Amz-Target: AWSCognitoIdentityService.GetId 
 Optional([])
2023-07-28T13:58:42+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-identity.us-west-2.amazonaws.com/?")with max connections: 50
2023-07-28T13:58:43+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/?")
2023-07-28T13:58:43+0200 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 User-Agent: aws-sdk-swift/1.0 api/cognito-identity/1.0 os/iOS/16.4.0 lang/swift/5.8 lib/amplify-swift/2.12.0, 
Content-Length: 1221, 
Content-Type: application/x-amz-json-1.1, 
x-amz-user-agent: aws-sdk-swift/1.0, 
X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity, 
Host: cognito-identity.us-west-2.amazonaws.com 
 Optional([])
2023-07-28T13:58:43+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-identity.us-west-2.amazonaws.com/?")with max connections: 50
2023-07-28T13:58:44+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/?")
Signin result: AuthSignInResult(nextStep: Amplify.AuthSignInStep.done)
⏰ signIn() finished! 5.262481343

Repository also has a amplify-v1 branch to showcase that it takes significantly shorter to sign in with amplify v1 eg 1.30. This can be seen by the same print statements

⏰ signIn() clicked!
Signin result: success(Amplify.AuthSignInResult(nextStep: Amplify.AuthSignInStep.done))
⏰ signIn() finished! 0.7506569623947144

@smbrmoyo
Copy link

@jbelkins I have created a sample project to demonstrate the issue. You can find it here:

https://github.com/fzy-spyro/AmplifySlowSignin

on "main" branch I am using amplify 2.15.1 where signin usually takes > 3 seconds. Logs from the execution are eg:

⏰ signIn() clicked!
2023-07-28T13:58:42+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/?")
2023-07-28T13:58:42+0200 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 Content-Length: 1225, 
Content-Type: application/x-amz-json-1.1, 
x-amz-user-agent: aws-sdk-swift/1.0, 
Host: cognito-identity.us-west-2.amazonaws.com, 
User-Agent: aws-sdk-swift/1.0 api/cognito-identity/1.0 os/iOS/16.4.0 lang/swift/5.8 lib/amplify-swift/2.12.0, 
X-Amz-Target: AWSCognitoIdentityService.GetId 
 Optional([])
2023-07-28T13:58:42+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-identity.us-west-2.amazonaws.com/?")with max connections: 50
2023-07-28T13:58:43+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/?")
2023-07-28T13:58:43+0200 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 User-Agent: aws-sdk-swift/1.0 api/cognito-identity/1.0 os/iOS/16.4.0 lang/swift/5.8 lib/amplify-swift/2.12.0, 
Content-Length: 1221, 
Content-Type: application/x-amz-json-1.1, 
x-amz-user-agent: aws-sdk-swift/1.0, 
X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity, 
Host: cognito-identity.us-west-2.amazonaws.com 
 Optional([])
2023-07-28T13:58:43+0200 info SerialExecutor : [Logging] Creating connection pool for Optional("https://cognito-identity.us-west-2.amazonaws.com/?")with max connections: 50
2023-07-28T13:58:44+0200 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/?")
Signin result: AuthSignInResult(nextStep: Amplify.AuthSignInStep.done)
⏰ signIn() finished! 5.262481343

Repository also has a amplify-v1 branch to showcase that it takes significantly shorter to sign in with amplify v1 eg 1.30. This can be seen by the same print statements

⏰ signIn() clicked!
Signin result: success(Amplify.AuthSignInResult(nextStep: Amplify.AuthSignInStep.done))
⏰ signIn() finished! 0.7506569623947144

This might be a little out of context, but is there a way to turn off the logs during the execution of all the Auth functions? I've even tried to set the LogLevel to .none when configuring Amplify and it still doesn't help

@sebsto
Copy link
Author

sebsto commented Aug 11, 2023

@smbrmoyo
These logs are generated by the AWS SDK, you can reduce the SDK verbosity like this :

        // reduce verbosity of AWS SDK
        SDKLoggingSystem.initialize(logLevel: .warning)

Do not forget to import ClientRuntime

Here is how I do it
https://github.com/sebsto/amplify-memories/blob/main/app/Memories/Backend.swift

@smbrmoyo
Copy link

It works. Thank you very much!

@fzy-github
Copy link

@jbelkins Is there any news here?

@jbelkins
Copy link

@fzy-spyro Thank you much for the sample project you linked above. I created an account with it, then repeatedly logged in to test login times. It was immensely useful for troubleshooting this issue.

The issue appears to be that HTTP connections are not being reused when appropriate. The login request above requires four HTTP requests to complete, and a new connection is being made for each one. When connections are properly reused, signin times appear to be comparable to the Amplify v1 branch.

We will prepare a fix for aws-sdk-swift, which will then need to be shipped in amplify-swift. For visibility, the problem in aws-sdk-swift is tracked in awslabs/aws-sdk-swift#1035.

@fzy-github
Copy link

@jbelkins Thanks for the update. I'm glad that the project helped to pinpoint the issues. Looking forward for the fix :)

@fzy-github
Copy link

@jbelkins

A have a question on how the http-sdk works. While doing investigation of this issue on my end I was using a proxy tool to intercept http traffic to understand if this was a network issue etc. What I've observed that with Amplify v1 SDK I could easily see http calls to cognito in proxy (eg proxyman) but when using Amplify V2 those calls were not there. What was more suprprising was that I wasn't able to intercept cognito calls only, graphql or REST request going through eg. APIPlugin were easily tracable in the proxy.

Does the cognito http-sdk has something to do with it? Does it somehow hide this requests from proxies?

@lawmicha
Copy link
Contributor

Hi @fzy-spyro, feel free to open another issue directly with the swift SDK to get more visibility on your last question here: https://github.com/awslabs/aws-sdk-swift/issues

@fzy-github
Copy link

Thanks @lawmicha will do. and regarding the fix for the signin time - I see that the sdk team has released the fix: awslabs/aws-sdk-swift#1035
when can we expect the change to be included in amplify update?

@sebsto
Copy link
Author

sebsto commented Nov 10, 2023

@fzy-spyro amplify 2.22.0 has been released yesterday. It includes SDK 0.31.0 with the fix you mentioned.

https://github.com/aws-amplify/amplify-swift/releases/tag/2.22.0

Please try it out as soon as you can and report back the status here.

@atierian atierian closed this as completed Dec 8, 2023
@fzy-github
Copy link

fzy-github commented Jan 29, 2024

@sebsto @lawmicha I am still seeing the same behavior with amplify sdk 2.25.5. signin requests lasts for ~3-4 seconds.

logs:

⏰ signIn() clicked!
2024-01-29T13:44:22+0100 info CognitoIdentityProviderClient : [Logging] Request: POST https:443 
 Path: / 
 X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth, 
Content-Type: application/x-amz-json-1.1, 
Host: cognito-idp.us-west-2.amazonaws.com, 
Content-Length: 6684, 
User-Agent: aws-sdk-swift/1.0 ua/2.0 api/cognito_identity_provider#1.0 os/ios#17.0.1 lang/swift#5.9 cfg/retry-mode#legacy 
 nil
2024-01-29T13:44:22+0100 info SerialExecutor : [Logging] Creating connection pool for cognito-idp.us-west-2.amazonaws.com with max connections: 50
2024-01-29T13:44:22+0100 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/")
2024-01-29T13:44:22+0100 info CRTClientEngine : [Logging] Using HTTP/1.1 connection
2024-01-29T13:44:22+0100 info HttpContent : [Logging] read 6684 bytes from data
2024-01-29T13:44:22+0100 info CRTClientEngine : [Logging] Main headers received
2024-01-29T13:44:22+0100 info CRTClientEngine : [Logging] Body chunk received
2024-01-29T13:44:22+0100 info CRTClientEngine : [Logging] Request/response completed
2024-01-29T13:44:23+0100 info CognitoIdentityProviderClient : [Logging] Request: POST https:443 
 Path: / 
 Content-Type: application/x-amz-json-1.1, 
X-Amz-Target: AWSCognitoIdentityProviderService.RespondToAuthChallenge, 
Content-Length: 7858, 
User-Agent: aws-sdk-swift/1.0 ua/2.0 api/cognito_identity_provider#1.0 os/ios#17.0.1 lang/swift#5.9 cfg/retry-mode#legacy, 
Host: cognito-idp.us-west-2.amazonaws.com 
 nil
2024-01-29T13:44:23+0100 info SerialExecutor : [Logging] Creating connection pool for cognito-idp.us-west-2.amazonaws.com with max connections: 50
2024-01-29T13:44:23+0100 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-idp.us-west-2.amazonaws.com/")
2024-01-29T13:44:23+0100 info CRTClientEngine : [Logging] Using HTTP/1.1 connection
2024-01-29T13:44:23+0100 info HttpContent : [Logging] read 7858 bytes from data
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Main headers received
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Body chunk received
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Request/response completed
2024-01-29T13:44:24+0100 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 Host: cognito-identity.us-west-2.amazonaws.com, 
X-Amz-Target: AWSCognitoIdentityService.GetId, 
User-Agent: aws-sdk-swift/1.0 ua/2.0 api/cognito_identity#1.0 os/ios#17.0.1 lang/swift#5.9 cfg/retry-mode#legacy, 
Content-Type: application/x-amz-json-1.1, 
Content-Length: 1225 
 nil
2024-01-29T13:44:24+0100 info SerialExecutor : [Logging] Creating connection pool for cognito-identity.us-west-2.amazonaws.com with max connections: 50
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/")
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Using HTTP/1.1 connection
2024-01-29T13:44:24+0100 info HttpContent : [Logging] read 1225 bytes from data
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Main headers received
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Body chunk received
2024-01-29T13:44:24+0100 info CRTClientEngine : [Logging] Request/response completed
2024-01-29T13:44:24+0100 info CognitoIdentityClient : [Logging] Request: POST https:443 
 Path: / 
 Content-Type: application/x-amz-json-1.1, 
User-Agent: aws-sdk-swift/1.0 ua/2.0 api/cognito_identity#1.0 os/ios#17.0.1 lang/swift#5.9 cfg/retry-mode#legacy, 
X-Amz-Target: AWSCognitoIdentityService.GetCredentialsForIdentity, 
Host: cognito-identity.us-west-2.amazonaws.com, 
Content-Length: 1221 
 nil
2024-01-29T13:44:24+0100 info SerialExecutor : [Logging] Creating connection pool for cognito-identity.us-west-2.amazonaws.com with max connections: 50
2024-01-29T13:44:25+0100 info CRTClientEngine : [Logging] Connection was acquired to: Optional("https://cognito-identity.us-west-2.amazonaws.com/")
2024-01-29T13:44:25+0100 info CRTClientEngine : [Logging] Using HTTP/1.1 connection
2024-01-29T13:44:25+0100 info HttpContent : [Logging] read 1221 bytes from data
2024-01-29T13:44:25+0100 info CRTClientEngine : [Logging] Main headers received
2024-01-29T13:44:25+0100 info CRTClientEngine : [Logging] Body chunk received
2024-01-29T13:44:25+0100 info CRTClientEngine : [Logging] Request/response completed
Signin result: AuthSignInResult(nextStep: Amplify.AuthSignInStep.done)
⏰ signIn() finished! 3.8088619709014893

I've raised new issue: #3486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth category bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants