title: How to create Elastic IP association with an EC2 instance using AWS CDK?
body: <p>In AWS CDK, I have an EC2 instance and Elastic IP created as follows:</p>
  
  <pre><code>    // EC2 Instance
      let ec2Instance = new ec2.Instance(this, "EC2Instance", {
          instanceType: ec2.InstanceType.of(InstanceClass.T2, InstanceSize.MICRO),
          vpc: vpc,
          securityGroup: securityGroupEc2,
          keyName: Config.keyPairName,
          machineImage: new ec2.GenericLinuxImage({"eu-west-1": Config.ec2ImageAmi}),
          blockDevices: [{deviceName: "/dev/sda1", volume: ec2.BlockDeviceVolume.ebs(30)}]
      });
  
      // Elastic IP
      let eip = new ec2.CfnEIP(this, "Ip");
  </code></pre>
  
  <p>I have difficulties to understand how I can declare an association between these, as I can not perceive using <a href="https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.CfnEIPAssociation.html" rel="nofollow noreferrer">AWS CDK documentation</a> how to declare that. Seems that I need <code>AWS::EC2::EIPAssociation.EIP: string</code> to supply and I am missing as to how to get it from the <code>eip</code> object. </p>