question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-backup): Resolution error: stack.regionalFact is not a function

See original GitHub issue

What is the problem?

Trying to follow the guide in https://docs.aws.amazon.com/cdk/api/v1/docs/aws-backup-readme.html to setup backups for tables.

Reproduction Steps

Here’s the simple stack file I tried to reproduce from given the backup guide mentioned above:

import * as cdk from "@aws-cdk/core";
import * as dynamodb from "@aws-cdk/aws-dynamodb";
import * as backup from "@aws-cdk/aws-backup";

export class DynamoTestStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
        super(scope, id);

        const plan = backup.BackupPlan.dailyWeeklyMonthly5YearRetention(
            this,
            "Plan"
        );

        const myTable = dynamodb.Table.fromTableName(this, 'Table', 'testtable');

        plan.addSelection("Selection", {
            resources: [backup.BackupResource.fromDynamoDbTable(myTable)]
        });
    }
}

What did you expect to happen?

cdk should have synthesized a template that has logic to backup the table.

What actually happened?

It errors out saying stack.regionalFact isn’t a function although going through the source code shows it is here https://github.com/aws/aws-cdk/blob/77144f5a1072feea7409b4222fbc80bd2bc86e71/packages/%40aws-cdk/core/lib/stack.ts#L825 Tracing the issue, it may lie in aws-iam rather than aws-backup.

Stack trace (censored out identifying information from paths):

infra/cdk/node_modules/@aws-cdk/aws-backup/node_modules/@aws-cdk/aws-iam/lib/principals.ts:540
    return stack.regionalFact(
                 ^
TypeError: Resolution error: Resolution error: Resolution error: Resolution error: stack.regionalFact is not a function.
Object creation stack:
  at stack traces disabled.
Object creation stack:
  at stack traces disabled..
    at ServicePrincipalToken.resolve (infra/cdk/node_modules/@aws-cdk/aws-backup/node_modules/@aws-cdk/aws-iam/lib/principals.ts:540:18)
    at RememberingTokenResolver.resolveToken (infra/cdk/node_modules/@aws-cdk/core/lib/resolvable.ts:80:24)
    at RememberingTokenResolver.resolveToken (infra/cdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:286:18)
    at resolve (infra/cdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:212:51)
    at Object.resolve [as mapToken] (infra/cdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:119:77)
    at TokenizedStringFragments.mapTokens (infra/cdk/node_modules/@aws-cdk/core/lib/string-fragments.ts:65:33)
    at RememberingTokenResolver.resolveString (infra/cdk/node_modules/@aws-cdk/core/lib/resolvable.ts:99:22)
    at RememberingTokenResolver.resolveString (infra/cdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:290:23)
    at resolve (infra/cdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:170:48)
    at Object.resolve (infra/cdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:119:77)   

CDK CLI Version

1.134.0 (build dd5e12d)

Framework Version

No response

Node.js Version

v16.13.0

OS

macOS Catalina

Language

Typescript

Language Version

3.9.7

Other information

Something interesting is that I looked around for other examples of this and came across this repository https://github.com/boostercloud/rocket-backup-aws-infrastructure I downgraded all of my aws-cdk packages to 1.67.0 to match their versions and cdk synth worked afterward. However, it’s unideal to be on version 1.67.0 due to other stacks.

Initially, my dependencies were 1.137.0 for aws-backup, aws-dynamodb, and aws-core.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
kaizencccommented, Jan 4, 2022

I am able to cdk synth the stack you provided successfully both on the latest v1 version (1.137).

It’s likely that the issue is that your dependencies were not aligned. stack.regionalFact was added 20 days ago, and released in v 1.137. I was able to reproduce the error you are describing by forcing my aws-backup dependency to 1.137 while keeping core at 1.136. backup is searching for a function added in 1.137 but it only has 1.136 available.

Please update @aws-cdk/core to 1.137. I’m almost certain that that will solve the issue.

2reactions
peterwoodworthcommented, Jan 4, 2022

Something to note - if you use CDK v2, all the libraries are condensed into one package, and you won’t be able to run into these types of errors anymore!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS CDK stack.regionalFact is not a function
The problem was a mismatch between the aws-cdk packages installed and the cdk global package. Make sure to have both updated to the...
Read more >
class Stack (construct) · AWS CDK
The AWS environment (account/region) where this stack will be deployed. ... is not given, it is an error if the fact is unknown...
Read more >
Troubleshooting AWS Backup
Find information to help you troubleshoot problems with AWS Backup.
Read more >
class NestedStack (construct) · AWS CDK
Look up a fact value for the given fact for the region of this stack. Will return a definite value only if the...
Read more >
aws-cdk/core module
As a final note: Stack s are not a unit of reuse. ... in a different stack, as long as they are in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found