title: Creating SQS using AWS Java SDK for role-based, federated user without having credentials
body: <p>I am trying to create SQS using AWS Java SDK. I do not have access-key and key-id, I go into AWS console with a link provided by my company. It is a role-based, SAML access (federated login). Whenever I try creating SQS from Java code, either I get 403 error (if I do not write any code for credentials), or I run into more errors if I try with code specified in AWS blogs for federated users.</p>
  
  <p>I have tried following code but it does not work:</p>
  
  <pre><code>AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder
                      .standard()
                      .withCredentials(new DefaultAWSCredentialsProviderChain())
                      .withRegion(Regions.EU_WEST_1)
                      .build();
  
  GetFederationTokenRequest getFederationTokenRequest = new GetFederationTokenRequest();
              getFederationTokenRequest.setDurationSeconds(7200);
              getFederationTokenRequest.setName("&lt;username&gt;@&lt;company&gt;.com");
  
  // Define the policy and add it to the request.
              Policy policy = new Policy();
              policy.withStatements(new Statement(Statement.Effect.Allow)
                      .withActions(SQSActions.AllSQSActions)
                      .withResources(new Resource("arn:aws:sqs:::test-queue")));
              getFederationTokenRequest.setPolicy(policy.toJson());
  
  // Get the temporary security credentials.
              GetFederationTokenResult federationTokenResult = stsClient.getFederationToken(getFederationTokenRequest);
  
  Credentials sessionCredentials = federationTokenResult.getCredentials();
  
  // Package the session credentials as a BasicSessionCredentials BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(
                      sessionCredentials.getAccessKeyId(),
                      sessionCredentials.getSecretAccessKey(),
                      sessionCredentials.getSessionToken());
  
  AmazonSQSAsync amazonSQS = AmazonSQSAsyncClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(basicSessionCredentials))
                      .withRegion(Regions.EU_WEST_1)
                      .build();
  
  CreateQueueRequest request = new CreateQueueRequest("wifi-test-queue");
  
  String result = amazonSQS.createQueue(request).getQueueUrl();
  </code></pre>
  
  <p>The above code does not work unfortunately.
  I am sure that my account has permissions to create/access SQS because I am able to achieve similar things with Terraform.</p>
  
  <p>Can someone please help me how to create a resource with such account?</p>