While updating the codeBuild image version in AWS getting the error as “the policy is attached to 0 entities but it must be attached to a single role”.

Error:
The policy is attached to 0 entities but it must be attached to a single role.
Details:
This error occurs due to the checkbox selected as “Allow AWS codeBuild to modify this service role so it can be used with the build project”. and the generated policy is not attached to the service role.
Whenever we select the checkbox “Allow AWS codeBuild to modify this service role so it can be used with the build project”, CodeBuild creates a policy with format “CodeBuildBasePolicy-project-name-region”. and if policy is already created with the previous builds, it must be attached to the service role of that codeBuild.
Solution:
Attach the policy as "CodeBuildBasePolicy-project-name-region"
for the service role of the c
odeBuild.
Follow the below steps to attach the policy: