首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NetworkInterfaces在CfnNetworkInterface中的错误

NetworkInterfaces在CfnNetworkInterface中的错误
EN

Stack Overflow用户
提问于 2020-04-01 08:11:29
回答 1查看 299关注 0票数 2

我正在尝试用CloudFormation生成C#文件。不幸的是,无论我作为NetworkInterfaces在CfnInstance中传递什么,我都会得到一个错误。我翻阅了整个文档,找不到解决问题的办法。

这是我的C#堆栈。

代码语言:javascript
复制
public class CFStack : Amazon.CDK.Stack
    {
        public CFStack(Construct parent, string id) : base(parent, id)
        {
            var vpc = new CfnVPC(this, "VPC", new CfnVPCProps()
            {
                CidrBlock = "10.0.0.0/16",
                EnableDnsHostnames = true,
                EnableDnsSupport = true,
                InstanceTenancy = "default"
            });

            var sg = new CfnSecurityGroup(this, "SG", new CfnSecurityGroupProps()
            {
                GroupDescription = "CF Security group",
                GroupName = "CF SG",
                VpcId = vpc.Ref,
            });

            var subnet = new CfnSubnet(this, "Subnet", new CfnSubnetProps()
            {
                CidrBlock = "10.0.0.0/24",
                MapPublicIpOnLaunch = true,
                VpcId = vpc.Ref,
            });

            new CfnSecurityGroupIngress(this, "ingress", new CfnSecurityGroupIngressProps()
            {
                GroupId = sg.Ref,
                FromPort = 3389,
                ToPort = 3389,
                CidrIp = "213.155.147.202/32",
                IpProtocol = "tcp"
            });

            new CfnSecurityGroupEgress(this, "egress", new CfnSecurityGroupEgressProps()
            {
                GroupId = sg.Ref,
                FromPort = 80,
                ToPort = 444,
                CidrIp = "0.0.0.0/0",
                IpProtocol = "tcp",
            });

            var blockmapping = new CfnInstance.BlockDeviceMappingProperty()
            {
                DeviceName = "/dev/sdh",
                Ebs = new CfnInstance.EbsProperty()
                {
                    VolumeType = EbsDeviceVolumeType.GP2.ToString(),
                    DeleteOnTermination = true,
                    VolumeSize = 65,
                }
            };

            var networkInterface = new CfnNetworkInterface(this, "NetworkInterface", new CfnNetworkInterfaceProps()
            {
                GroupSet = new[] { sg.ToString() },
                SubnetId = subnet.Ref
            });

            new CfnInstance(this, "EC2", new CfnInstanceProps()
            {
                NetworkInterfaces = new[] { networkInterface },
                BlockDeviceMappings = new[] { blockmapping },
                ImageId = "ami-id",
                InstanceType = "m5.xlarge",
                KeyName = "keyName",
                UserData = "test"
            });
        }
    }

不幸的是,异常的堆栈跟踪并没有清楚地说明问题。下面是堆栈跟踪本身:

代码语言:javascript
复制
Amazon.JSII.Runtime.JsiiException: Amazon.JSII.Runtime.JsiiException: Resolution error: Resolution error: Trying to resolve() a Construct at /Resources/${Token[MihailStack.EC2.LogicalID.32]}/Properties/networkInterfaces/0/node/_actualNode.
Object creation stack:
  at new Intrinsic (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\private\intrinsic.js:20:44)
  at new PostResolveToken (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\util.js:72:9)
  at Object.ignoreEmpty (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\util.js:32:12)
  at CfnInstance._toCloudFormation (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\cfn-resource.js:214:44)
  at C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\stack.js:833:76
  at Object.findTokens (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\private\resolve.js:126:13)
  at Stack.findTokens (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\stack.js:833:42)
  at Stack.prepare (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\stack.js:544:29)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:51
  at Kernel._wrapSandboxCode (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8298:20)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:25
  at Kernel._ensureSync (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8274:20)
  at Kernel.invoke (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7664:26)
  at KernelHost.processRequest (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7372:28)
  at KernelHost.completeCallback (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7345:25)
  at KernelHost.callbackHandler (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7326:33)
  at Stack.value (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8012:41)
  at Stack.onPrepare (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\construct-compat.js:66:14)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:51
  at Kernel._wrapSandboxCode (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8298:20)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:25
  at Kernel._ensureSync (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8274:20)
  at Kernel.invoke (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7664:26)
  at KernelHost.processRequest (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7372:28)
  at KernelHost.completeCallback (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7345:25)
  at KernelHost.callbackHandler (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7326:33)
  at Stack.value (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8012:41)
  at Node.prepare (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\constructs\lib\construct.js:371:27)
  at Node.synthesize (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\constructs\lib\construct.js:333:14)
  at Function.synth (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\construct-compat.js:165:26)
  at App.synth (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\app.js:71:59)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:51
  at Kernel._wrapSandboxCode (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8298:20)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:25
  at Kernel._ensureSync (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8274:20)
  at Kernel.invoke (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7664:26)
  at KernelHost.processRequest (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7372:28)
  at KernelHost.run (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7312:14)
  at Immediate._onImmediate (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7315:37)
  at processImmediate (internal/timers.js:439:21).
Object creation stack:
  at new Intrinsic (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\private\intrinsic.js:20:44)
  at new PostResolveToken (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\util.js:72:9)
  at CfnInstance._toCloudFormation (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\cfn-resource.js:212:39)
  at C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\stack.js:833:76
  at Object.findTokens (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\private\resolve.js:126:13)
  at Stack.findTokens (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\stack.js:833:42)
  at Stack.prepare (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\stack.js:544:29)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:51
  at Kernel._wrapSandboxCode (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8298:20)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:25
  at Kernel._ensureSync (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8274:20)
  at Kernel.invoke (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7664:26)
  at KernelHost.processRequest (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7372:28)
  at KernelHost.completeCallback (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7345:25)
  at KernelHost.callbackHandler (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7326:33)
  at Stack.value (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8012:41)
  at Stack.onPrepare (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\construct-compat.js:66:14)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:51
  at Kernel._wrapSandboxCode (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8298:20)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:25
  at Kernel._ensureSync (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8274:20)
  at Kernel.invoke (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7664:26)
  at KernelHost.processRequest (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7372:28)
  at KernelHost.completeCallback (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7345:25)
  at KernelHost.callbackHandler (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7326:33)
  at Stack.value (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8012:41)
  at Node.prepare (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\constructs\lib\construct.js:371:27)
  at Node.synthesize (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\constructs\lib\construct.js:333:14)
  at Function.synth (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\construct-compat.js:165:26)
  at App.synth (C:\Users\hmh\AppData\Local\Temp\jsii-kernel-lGLo4x\node_modules\@aws-cdk\core\lib\app.js:71:59)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:51
  at Kernel._wrapSandboxCode (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8298:20)
  at C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7665:25
  at Kernel._ensureSync (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:8274:20)
  at Kernel.invoke (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7664:26)
  at KernelHost.processRequest (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7372:28)
  at KernelHost.run (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7312:14)
  at Immediate._onImmediate (C:\Users\hmh\AppData\Local\Temp\ys3l4mjc.q1n\jsii-runtime.js:7315:37)
  at processImmediate (internal/timers.js:439:21)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.Invoke(InvokeRequest request)
   at Amazon.JSII.Runtime.Services.Client.Invoke(ObjectReference objectReference, String method, Object[] arguments)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass17_0`1.<InvokeInstanceMethod>b__1(IClient client, Object[] args)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceVoidMethod(Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.CDK.Stack.Prepare()
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.Invoke(InvokeRequest request)
   at Amazon.JSII.Runtime.Services.Client.Invoke(ObjectReference objectReference, String method, Object[] arguments)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass17_0`1.<InvokeInstanceMethod>b__1(IClient client, Object[] args)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<InvokeMethodCore>g__GetResult|18_0[T](<>c__DisplayClass18_0`1& )
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeMethodCore[T](JsiiMethodAttribute methodAttribute, Object[] arguments, Func`3 beginFunc, Func`3 invokeFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceMethod[T](Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.InvokeInstanceVoidMethod(Type[] parameterTypes, Object[] arguments, String methodName)
   at Amazon.CDK.Construct.OnPrepare()

我也曾试图通过

代码语言:javascript
复制
NetworkInterfaces = networkInterface
NetworkInterfaces = networkInterface.ToString()
NetworkInterfaces = new[] {networkInterface}
NetworkInterfaces = new[] {networkInterface.ToString()}

如果我从NetworkInteraces中删除CfnNetworkInterface属性,那么上面的代码可以正常工作。

我不明白问题出在哪里。我更改的所有内容都会导致上述情况下的相同异常。任何帮助都是非常感谢的。

提前谢谢你。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-02 00:26:01

我能够使用TypeScript重新创建并修复API问题。我能合成堆栈。我相信这同样适用于C#。

代码语言:javascript
复制
new CfnInstance(this, "EC2", {
  networkInterfaces: [{
    deviceIndex: '0',
    groupSet: [sg.toString()],
    subnetId: subnet.ref
  }],
  imageId: "ami-id",
  instanceType: "t2.micro",
  keyName: "keyName",
  userData: "test"
});

问题在于CfnNetworkInterfaceCfnInstance中的使用。CfnInstance中的属性CfnInstance.NetworkInterfaceProperty or cdk.IResolvable需要一个类型为CfnInstance.NetworkInterfaceProperty or cdk.IResolvable的数组。您现在提供给它的内容(CfnNetworkInterface)与预期的类型不匹配。我也很困惑地发现,我无法在上面的TS代码中导入CfnInstance.NetworkInterfaceProperty,但能够将对象表示法强制转换为IResolvable

还请注意,当您使用CfnInstance.NetworkInterfaceProperty时,您还必须提供deviceIndex。希望这将解决C#代码中的问题。

PS:为了简洁起见,我已经将blockDeviceMappings从我的方法中删除了。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60966273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档