# How set AWS::Cognito::\* in a different region than the default provider: region

**URL:** <https://forum.serverless.com/t/how-set-aws-in-a-different-region-than-the-default-provider-region/10553>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [February 13, 2020, 6:32pm UTC](https://forum.serverless.com/t/how-set-aws-in-a-different-region-than-the-default-provider-region/10553 "2020-02-13T18:32:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilsoncav](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gilsoncav/32/3983_2.png) [@gilsoncav](https://forum.serverless.com/u/gilsoncav)\
**Post date:** [February 13, 2020, 6:32pm UTC](https://forum.serverless.com/t/how-set-aws-in-a-different-region-than-the-default-provider-region/10553/1 "2020-02-13T18:32:25Z")

</div>

Hi!  
Cognito isn’t available in my aws region (sa-east-1). So how do i set a different region for the Cognito resources as the example bellow:

```
Resources:
  # The federated identity for our user pool to auth with
  CognitoIdentityPool:
    Type: AWS::Cognito::IdentityPool
    Properties:
      # Generate a name based on the stage
      IdentityPoolName: ${self:custom.stage}IdentityPool
      # Don't allow unathenticated users
      AllowUnauthenticatedIdentities: false
      # Link to our User Pool
      CognitoIdentityProviders:
        - ClientId:
            Ref: CognitoUserPoolClient
          ProviderName:
            Fn::GetAtt: ["CognitoUserPool", "ProviderName"]

  # IAM roles
  CognitoIdentityPoolRoles:
    Type: AWS::Cognito::IdentityPoolRoleAttachment
    Properties:
      IdentityPoolId:
        Ref: CognitoIdentityPool
      Roles:
        authenticated:
          Fn::GetAtt: [CognitoAuthRole, Arn]

  # IAM role used for authenticated users
  CognitoAuthRole:
    Type: AWS::IAM::Role
    Properties:
      Path: /
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: 'Allow'
            Principal:
              Federated: 'cognito-identity.amazonaws.com'
            Action:
              - 'sts:AssumeRoleWithWebIdentity'
            Condition:
              StringEquals:
                'cognito-identity.amazonaws.com:aud':
                  Ref: CognitoIdentityPool
              'ForAnyValue:StringLike':
                'cognito-identity.amazonaws.com:amr': authenticated
      Policies:
        - PolicyName: 'CognitoAuthorizedPolicy'
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: 'Allow'
                Action:
                  - 'mobileanalytics:PutEvents'
                  - 'cognito-sync:*'
                  - 'cognito-identity:*'
                Resource: '*'

              # Allow users to invoke our API
              - Effect: 'Allow'
                Action:
                  - 'execute-api:Invoke'
                Resource:
                  Fn::Join:
                    - ''
                    -
                      - 'arn:aws:execute-api:'
                      - Ref: AWS::Region
                      - ':'
                      - Ref: AWS::AccountId
                      - ':'
                      - Ref: ApiGatewayRestApi
                      - '/*'

              # Allow users to upload attachments to their
              # folder inside our S3 bucket
              - Effect: 'Allow'
                Action:
                  - 's3:*'
                Resource:
                  - Fn::Join:
                      - ''
                      -
                        - Fn::GetAtt: [AttachmentsBucket, Arn]
                        - '/private/'
                        - '$'
                        - '{cognito-identity.amazonaws.com:sub}/*'

# Print out the Id of the Identity Pool that is created
Outputs:
  IdentityPoolId:
    Value:
      Ref: CognitoIdentityPool
```
