Date:

Share:

How To Solve “Rate exceeded for operation ‘AWS::CloudFront::Distribution’.” Error?

Related Articles

This article is sponsored by AWS and is part of my AWS series.

the problem

Recently at work, I had to deploy ~80 CloudFront instances, each with its own certificate, pointing to a single S3 bucket as its origin, all in one CloudFormation file.

However, when running the CloudFormation template, it kept failing with the below message.

“Class exception for operation ‘AWS::CloudFront::Distribution’.”

The CloudFormation file did succeed when the number of CloudFront instances was around 20.

I didn’t want to split the deployment into different CloudFormation templates or create multiple stacks.

As much as possible, I wanted to keep everything in one file so that it can be easily managed.

the solution

CloudFormation, when creating resources, tries to create all independent resources at the same time.

In my scenario, because the CloudFront instances were independent of each other and only depended on the single S3.

Because of this, CloudFormation tries to start and create all ~80 CloudFronts at the same time, resulting in Rate exceeded for operation Error.

To avoid CloudFormation, creating all the resources at the same time, we can introduce the DependsOn feature on the resources.

With the DependsOn attribute you can specify that the creation of a specific resource follows another. When you add a DependsOn attribute to a resource, that resource is created only after the resource specified in the DependsOn attribute is created.

DependsOn It only depends on deployment time and does not create anything specific in the actual resources in AWS.

adding the DependsOn The feature forces CloudFormation to deploy the resources in the order they depend on.

To fix my particular problem, I attached the CloudFront build to 10. So as shown in the image below, in the CloudFormation template, I inserted a fake dependency between resources in each batch and that of the previous batch.

The first 10 sites are created first, followed by sites 11-20, which DependsOn All sites from 1-10 that will be created.

Once this is done, it moves to the next batch, which depends on all the websites in the previous batch.

You can see additional batch dependencies in the image below, where Website65 depends on all the sites in the batch before it (site 51-60), and website 71 depends on the batch before it (site 61-70).

God DependsOn A feature helps to limit and maintain the number of CloudFront instances that are created at a time.

I hope this helps you in case you run into a similar situation!

Source

Popular Articles