-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[aws-ec2] lookup functions ignore --profile #31036
Comments
@ps-spark Good afternoon. As noted in comment in your stack entry point where CDK app is initialized: ...
/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
... Python (app.py)
Please uncomment the relevant lines which initializes Thereafter, if you run For example, for the following CDK app and stack: #!/usr/bin/env python3
import os
import aws_cdk as cdk
from cdktest_python.cdktest_python_stack import CdktestPythonStack
app = cdk.App()
CdktestPythonStack(app, "CdktestPythonStack",
# If you don't specify 'env', this stack will be environment-agnostic.
# Account/Region-dependent features and context lookups will not work,
# but a single synthesized template can be deployed anywhere.
# Uncomment the next line to specialize this stack for the AWS Account
# and Region that are implied by the current CLI configuration.
env=cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')),
# Uncomment the next line if you know exactly what Account and Region you
# want to deploy the stack to. */
#env=cdk.Environment(account='123456789012', region='us-east-1'),
# For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
)
app.synth() cdktest_python\cdktest_python_stack.py from aws_cdk import (
# Duration,
Stack,
aws_ec2 as ec2,
)
from constructs import Construct
class CdktestPythonStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
ec2.Vpc.from_lookup(
self, "MyVpc",
is_default=True
) Running
Notice how Hope this helps. Thanks, |
Hi @ashishdhingra, Thank you, I read that but I already forgot it :( OK, it's not a bug then. I don't say that it's a beautiful solution but it works. Drawback: you have to define the env parameter in each stack you create. Best wishes, |
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
Hi Guys,
I'm trying to utilize the lookup functions in the ec2 package but it seems that they ignore the
env
settings in the AWS config file.If I execute
cdk diff --profile my-profile
the above lines fail with the following error message:If I explicitly define the
env
in the code then the above code is working.myenv = cdk.Environment(account="xxxx", region="eu-central-1")
Based on the docs
--profile
should be equivalent withenv
in the code. I don't want to hard-code the env!Expected Behavior
Lookup functions work with
cdk diff --profile my-profile
call.Current Behavior
RuntimeError(resp.error) from JavaScriptError(resp.stack)
Reproduction Steps
Use any lookup function from ec2 and try to run
cdk diff --profile my-profile
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.150.0
Framework Version
No response
Node.js Version
20.16.0
OS
Amazon Linux 2023
Language
Python
Language Version
3.10.12
Other information
No response
The text was updated successfully, but these errors were encountered: