![](/img/trans.png)
[英]jsii error when attempting to create a EC2 using Parameter via AWS CDK in python
[英]Unable to create EC2 with CDK using existing VPC in Python
尝试通过 CDK 2.0 访问 VPC,使用 python
from constructs import Construct
dirname = os.path.dirname(__file__)
class EC2InstanceStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
vpc = ec2.Vpc.from_lookup(self, "vpc", vpc_id='vpc-0912xxxxxxx94647')
出现以下错误,不确定如何在我的代码中传递帐户和区域
Traceback (most recent call last):
File "/Users/..../external/aws-cdk-examples/python/ec2/instance/app.py", line 86, in <module>
EC2InstanceStack(app, "ec2-instance")
File "/Users/...../projects/cdk_workshop/.venv/lib/python3.10/site-packages/jsii/_runtime.py", line 86, in __call__
inst = super().__call__(*args, **kwargs)
File "/Users/...../external/aws-cdk-examples/python/ec2/instance/app.py", line 49, in __init__
vpc = ec2.Vpc.from_lookup(self, "vpc", vpc_id='vpc-091234581ee4994647')
File "/Users/..../CDK/projects/cdk_workshop/.venv/lib/python3.10/site-packages/aws_cdk/aws_ec2/__init__.py", line 65179, in from_lookup
return typing.cast(IVpc, jsii.sinvoke(cls, "fromLookup", [scope, id, options]))
File "/Users/...../projects/cdk_workshop/.venv/lib/python3.10/site-packages/jsii/_kernel/__init__.py", line 148, in wrapped
return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
File "/Users/...../CDK/projects/cdk_workshop/.venv/lib/python3.10/site-packages/jsii/_kernel/__init__.py", line 405, in sinvoke
response = self.provider.sinvoke(
File "/Users/..../CDK/projects/cdk_workshop/.venv/lib/python3.10/site-packages/jsii/_kernel/providers/process.py", line 365, in sinvoke
return self._process.send(request, InvokeResponse)
File "/Users/..../CDK/projects/cdk_workshop/.venv/lib/python3.10/site-packages/jsii/_kernel/providers/process.py", line 329, in send
raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level. Configure "env" with an account and region when you define your stack.See https://docs.aws.amazon.com/cdk/latest/guide/environments.html for more details.
任何想法??
看起来答案在您的错误消息中:)
jsii.errors.JSIIError: Cannot retrieve value from context provider vpc-provider since account/region are not specified at the stack level. Configure "env" with an account and region when you define your stack.See https://docs.aws.amazon.com/cdk/latest/guide/environments.html for more details.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.