How automate the logo for aws hosted UI

Viewed 841

I have seen commands like this to setup a custom logo

aws cognito-idp set-ui-customization --user-pool-id us-XX-X_XXX --client-id ALL  --css "xxx" --region us-XX-X_XXX --image-file logo.png

But I am creating a stack with cloudformation and I like to automate this as well but I don't know how to do it because here https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpooluicustomizationattachment.html states that the logo is not supported and we need to use the set-ui-customization instead, so how can automate this process in order that when the stack is created I have the custom logo configured already?

2 Answers

You can create your own AWS CloudFormation custom resource. Custom resources enable you to write custom provisioning logic in templates that AWS CloudFormation runs anytime you create, update (if you changed the custom resource), or delete stacks.

In your case you could add a Lambda function that is triggered after your Amazon Cognito resources are deployed to add the customization through an API call.

Here's a link to the documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

And here is a great blog post going into many of the details: https://www.alexdebrie.com/posts/cloudformation-custom-resources/

I assume that you have the ability to run commands as part of your process to deploy CloudFormation.

Here's what worked for me:

  • used https://onlinepngtools.com/convert-png-to-base64 to convert the logo file into base 64

  • used the CLI to update both the logo AND the CSS at the same time

  • use the following command as part of my deployment process:

    aws cognito-idp set-ui-customization --user-pool-id us-west-2_ABC123 --client-id 112233 --image-file "base 64 text for the logo" --css ".banner-customizable {background-color: #303030;}"

I found that just updating the logo eliminated CSS I had previously set.

Related