Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssm: account/region are not specified at the stack level, but they are #27773

Closed
florianbepunkt opened this issue Oct 31, 2023 · 2 comments
Closed
Labels
@aws-cdk/aws-ssm Related to AWS Systems Manager bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@florianbepunkt
Copy link

Describe the bug

I have two stacks, A and B. Stack A adds sets an SSM param. Stack B consumes this param.

Now I get this error: Error: Cannot retrieve value from context provider ssm since account/region are not specified at the stack level. Configure "env" with an account and region when you define your stack.

But both stacks have account and region specified at the stack level like so:

const devenv = { account: "REDACTED", region: "eu-central-1" };
new Database(app, foo-database-test, {
stackName: "database",
env: devenv,
});

Expected Behavior

Account and region should be used from the stack level and the error should not be thrown.,

Current Behavior

Now I get this error: Error: Cannot retrieve value from context provider ssm since account/region are not specified at the stack level. Configure "env" with an account and region when you define your stack.

Reproduction Steps

import { Construct } from "constructs";
import * as cdk from "aws-cdk-lib";
import * as ssm from "aws-cdk-lib/aws-ssm";
import * as iam from "aws-cdk-lib/aws-iam";

const devenv = { account: "REDACTED", region: "eu-central-1" };

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

    const role = new iam.Role(this, "db-rw-role", {
      assumedBy: new iam.AccountRootPrincipal(),
      roleName: "test",
    });

    new ssm.StringParameter(this, "test-value-ssm", {
      parameterName: `/test-role-arn`,
      stringValue: role.roleArn,
    });
  }
}

const appA = new cdk.App();
new StackA(appA, `stack-a`, {
  stackName: "stacka",
  env: devenv,
});



export class StackB extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    const roleArn = ssm.StringParameter.valueFromLookup(this, `/test-role-arn`);
    const role = iam.Role.fromRoleArn(this, "role", roleArn);
  }
}

const appB = new cdk.App();
new StackB(appB, `stack-b`, {
  stackName: "stackb",
  env: devenv,
});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.103.1 (build 3bb19ac)

Framework Version

No response

Node.js Version

18

OS

MacOS

Language

TypeScript

Language Version

5.2.2

Other information

No response

@florianbepunkt florianbepunkt added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 31, 2023
@github-actions github-actions bot added the @aws-cdk/aws-ssm Related to AWS Systems Manager label Oct 31, 2023
@florianbepunkt
Copy link
Author

My bad, failed to pass the stack props to the stack constructor...

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ssm Related to AWS Systems Manager bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant