title: Error while calling an API with the AWS generated SDK for iOS, even though the user is logged in
body: <p>In my AWS project, I've created webservices using API Gateway and Lambda.</p>
  <p>I use AWSMobileClient for iOS to allow users to sign in / sign out using Cognito, and the API Gateway generated SDK for iOS (Swift) to be able to call APIs from that iOS app.</p>
  <p>Here is how i manage Cognito in my iOS app:</p>
  <ol>
  <li>First, initialize:</li>
  </ol>
  <pre class="lang-swift prettyprint-override"><code>AWSMobileClient.default().initialize { (userState: UserState?, error: Error?) in
      if (userState != nil)
      {
          print(&quot;AWSMobileClient initialize OK : \(userState.debugDescription)&quot;)
      }
      if (error != nil)
      {
          print(&quot;AWSMobileClient initialize error : \(String(describing: error))&quot;)
      }
  }
  </code></pre>
  <p>I got:</p>
  <pre><code>&quot;AWSMobileClient initialize OK : Optional(AWSMobileClient.UserState.signedOut)&quot;
  </code></pre>
  <ol start="2">
  <li>Then, sign in:</li>
  </ol>
  <pre class="lang-swift prettyprint-override"><code>AWSMobileClient.default().signIn(
      username: &quot;test@mail.com &quot;,
      password: &quot;abcd1234&quot;) { (signInResult: SignInResult?, error: Error?) in
  
      if (signInResult != nil)
      {
          if (signInResult!.signInState == SignInState.signedIn)
          {
              print(&quot;AWSMobileClient sign in OK&quot;)
          }
          else
          {
              print(&quot;AWSMobileClient sign in error&quot;)
          }
      }
      if (error != nil)
      {
          print(&quot;AWSMobileClient sign in error \(String(describing: error))&quot;)
      }
  }
  </code></pre>
  <p>I got:</p>
  <pre><code>&quot;AWSMobileClient sign in OK&quot;
  </code></pre>
  <ol start="3">
  <li>Now I want to call an API, which requires the user to be logged in:</li>
  </ol>
  <pre class="lang-swift prettyprint-override"><code>let credentialsProvider = AWSCognitoCredentialsProvider(
      regionType: AWSRegionType.EUCentral1,
      identityPoolId: &quot;eu-central-1:1234abcd-12ab-1234-1234-123456abcdef&quot;)
  let configuration = AWSServiceConfiguration(
      region: AWSRegionType.EUCentral1,
      credentialsProvider: credentialsProvider)
  AWSServiceManager.default()?.defaultServiceConfiguration = configuration
  
  let myTestModel: MyTestModel = MyTestModel()
  myTestModel.email = &quot;test@mail.com &quot;
  myTestModel.newEmail = &quot;test2@mail.com &quot;
  let client = MyMobileClient.default()
  client
      .signedInModifyInformationsAccountPost(contentType: &quot;application/json&quot;, body: myTestModel)
      .continueWith { (awsTask: AWSTask&lt;Empty&gt;) -&gt; Any? in
          if let awsError = awsTask.error as NSError? 
          {
              print(&quot;Error: \(awsError.userInfo)&quot;)
          }
          if let awsResult = awsTask.result
          {
              print(&quot;Success: \(awsResult)&quot;
          }
          return nil
      }
  </code></pre>
  <p>But here, I got the following error:</p>
  <pre><code>Message = &quot;User: arn:aws:sts::123456789012:assumed-role/wzj-dev-eu-central-1-identity-pool-non-authenticated/CognitoIdentityCredentials
  is not authorized to perform: execute-api:Invoke on resource:
  arn:aws:execute-api:eu-central-1:********1234:12345abcde/dev/POST/authenticated/modify-informations-account&quot;
  </code></pre>
  <p>And I really don't understand that message, since the user is logged in, and I got the confirmation right before calling that API that the user is properly logged in by checking with: <code>AWSMobileClient.default().currentUserStatus</code> (which is: <code>signedIn</code>). However, the IAM role that you can see in the error is..... the unauthenticated role!</p>
  <p>Even more surprisingly, if I quit my app, without signing out the user, and do it all over again, now it works, I can call the same API without any error.</p>
  <p><strong>EDIT:</strong></p>
  <p><em>That problem occurs only if I call another API <strong>BEFORE</strong> calling <code>modify-informations-account</code>. That other API can be called by both an authenticated and an unauthenticated user. If I don't call that other API, everything works fine.</em></p>
  <p>So what did I do wrong?</p>
  <p>Thanks.</p>