marc-dworkin
marc-dworkin

Reputation: 336

Using CloudFormation to configure Amazon Cognito Domain

I am using AWS Amplify in a React Native App. I set up my userpool with a domain via the console (https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-assign-domain-prefix.html), but have to manually remove and re-install it every time I make a chance to the backend\auth\poolname-cloudformation-template.yml.

Is there a CloudFormation setting that would allow me to set it up through there?

Thanks!

Upvotes: 0

Views: 2090

Answers (3)

Ashot
Ashot

Reputation: 1300

Here is how to do it in 2023:

UserPoolDNS:
   Type: AWS::Route53::RecordSet
   Properties:
     HostedZoneName: !Sub "${MainDomainName}."
     Name: !Sub "auth.${MainDomainName}."
     Type: A
     AliasTarget:
       HostedZoneId: Z2FDTNDATAQYW2
       DNSName: !GetAtt UserPoolDomain.CloudFrontDistribution
       EvaluateTargetHealth: false
UserPoolDomain:
   Type: AWS::Cognito::UserPoolDomain
   Properties:
     UserPoolId: !Ref UserPool
     Domain: !Join [ ".", [ "auth", !Ref MainDomainName ] ]
     CustomDomainConfig:
       CertificateArn: !Ref MainDomainCertificateARN

Upvotes: 1

Haider Ali
Haider Ali

Reputation: 481

Unfortunately, there is no Cloud Formation setting that allows to create an Amazon Cognito Domain. One work around for this is to create a Custom Cloud Formation resource backed by a Lambda and then creating the domain in Lambda through Boto 3.

Upvotes: 0

Related Questions