I'm working on a CloudFormation template using AWS::Serverless, which includes an AWS::Serverless::Api and an AWS::Cognito::UserPoolClient. The issue arises because the Rest API references the UserPool as an authorizer, while the UserPoolClient needs to refer back to the Rest API for the callback URL. Additionally, my lambda function requires environment variables that contain the Cognito client ID and secret. I've tried to set it up in this order: CognitoUserPool -> RestAPI -> CognitoUserPoolClient -> Lambda Function, but I keep hitting a circular dependency error during changeset generation. Is there a way to untangle this circular dependency? Is there a method to inject a common parameter, like the API URL base, into the template?
3 Answers
You might want to add DependsOn attributes to clarify the order for CloudFormation. Try adding DependsOn: RestAPI to your SwaggerUI resource and DependsOn: CognitoUserPool to the RestAPI resource. Just remember that DependsOn is not a property; it should be added alongside Properties. This approach could help resolve the confusion CF has with the dependencies.
When you mention 'SwaggerUI resource', are you referring to the AWS::Serverless::Function? I tried adding Dependencies earlier, but it still didn't solve the circular dependency issue, even with the linter indicating they might be unnecessary.
Have you thought about setting the callback URL using a Lambda function that invokes the AWS CLI after the Rest API is created? It could work without having to manage a multi-stage deployment, but you could also use a separate template for the Cognito part with a DependsOn condition to ensure the dependencies are created in the right order.
Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically