aws-cloudformation-fargate icon indicating copy to clipboard operation
aws-cloudformation-fargate copied to clipboard

Template for importing in outputs

Open mosesliao opened this issue 5 years ago • 3 comments

Do you have a way to import values from the VPC as stated

  VPCId:
    Description: The ID of the VPC that this stack is deployed in
    Value: !Ref 'VPC'
    Export:
      Name: !Join [ ':', [ !Ref 'AWS::StackName', 'VPCId' ] ]

How do I import VPC Id from the above export?

mosesliao avatar Apr 24 '20 09:04 mosesliao

You are not importing values from the vpc itself. Instead you are importing things about the vpc. You would have to use the name of the CloudFormation stack and suffix VPCId to it. I have not tried this specifically but it would be something like the following. The name that is being constructed is the CloudFormation stackname and VPCId concatenated and separated by a colon.

Fn::ImportValue:
  !Sub "${StackName}:VPCId"

That should return the vpcid.

dougtoppin avatar Apr 24 '20 12:04 dougtoppin

ok so the ${StackName} is the parameter of the stack? or is it something you have to hard code in?

mosesliao avatar Apr 24 '20 13:04 mosesliao

Sorry, I should have included that. If you are creating a new CloudFormation stack and need it to get that vpcid you would need to pass in the name of the stack that created it as a StackName parameter. Then the statement above would know the name of the exported vpcid value to use.

dougtoppin avatar Apr 24 '20 14:04 dougtoppin