<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>IT notes - remap</title>
    <subtitle>DBRE, AWS platform engineering, PostgreSQL, Linux, FreeBSD, and Rust reference notes.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://nbari.com/tags/remap/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://nbari.com"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2016-08-30T12:27:56+02:00</updated>
    <id>https://nbari.com/tags/remap/atom.xml</id>
    <entry xml:lang="en">
        <title>aws ec2 associate address</title>
        <published>2016-08-30T12:27:56+02:00</published>
        <updated>2016-08-30T12:27:56+02:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://nbari.com/aws-ec2-associate-address/"/>
        <id>https://nbari.com/aws-ec2-associate-address/</id>
        
        <content type="html" xml:base="https://nbari.com/aws-ec2-associate-address/">&lt;p&gt;If doing more than 100 requests implying the AWS CLI &lt;code&gt;associate-address&lt;/code&gt;
sub-command, subsequent calls will cost &lt;strong&gt;$0.10&lt;/strong&gt; each, so If doing to much
scale in/out or have a monitoring/automated tool that frecuenly make API calls using
this sub-command, the bill is not going to be cheap:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scale in  (remove instances)&lt;/li&gt;
&lt;li&gt;Scale out (add instances)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;/img/aws-ec2-associate-address.png&quot; alt=&quot;additional remap&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Long story short, The &lt;code&gt;associate-address&lt;/code&gt; sub-command, is an idempotent
operation, if you call &quot;aws ec2 associate-address&quot; with the same combination
of instance and EIP as the one currently in place, it won&#39;t return an error;
instead, it will return and count as successful, regardless of whether an actual
allocation was done or not. Consequently, being it counted as a successful
request, you&#39;ll be billed accordingly.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Idempotent operations take an important role, basically because you expect
that operation will not result in different results no matter how many times you
operate the idempotent operations. (Idempotent = Re-runnable).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This can be avoided by using private addresses and Load balancers, but in cases where
you need to deal with &lt;a rel=&quot;external&quot; href=&quot;http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html&quot;&gt;Elastic IP&#39;s&lt;/a&gt; this maybe an issue, mainly for monitoring scripts or periodic checks, or use the &lt;a rel=&quot;external&quot; href=&quot;http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-addresses.html&quot;&gt;describe-address&lt;/a&gt; and based on the result decide to use or not the &lt;code&gt;associate=address&lt;/code&gt; sub-command&lt;/p&gt;
&lt;h1 id=&quot;associate-address&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#associate-address&quot; aria-label=&quot;Anchor link for: associate-address&quot;&gt;🔗&lt;/a&gt;associate-address&lt;/h1&gt;
&lt;p&gt;Associates an Elastic IP address with an instance or a network interface. This
is an idempotent operation. If you perform the operation more than once, Amazon
EC2 doesn&#39;t return an error, example:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ aws ec2 associate-address --instance-id i-24ea6379 --allocation-id eipalloc-b58d24da&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;quot;AssociationId&amp;quot;: &amp;quot;eipassoc-b7b117df&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;http://docs.aws.amazon.com/cli/latest/reference/ec2/associate-address.html&lt;/p&gt;
&lt;p&gt;After running the previous command 100 times, the following requests will cost
each &lt;code&gt;$0.10 per Elastic IP address remap&lt;/code&gt; either the association didn&#39;t
succeed or if it was made to an existing IP.&lt;/p&gt;
&lt;p&gt;Basically this means that if you have something that periodically checks your
instances and tries to remap or ensure that your elastic IP is pointing you a
desired instance:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    10.0.1.3 ---&amp;gt; 58.41.28.32&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After doing 100 calls, the following request will cost &lt;strong&gt;$0.10&lt;/strong&gt; each.&lt;/p&gt;
&lt;h2 id=&quot;auto-scaling&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#auto-scaling&quot; aria-label=&quot;Anchor link for: auto-scaling&quot;&gt;🔗&lt;/a&gt;Auto scaling&lt;/h2&gt;
&lt;p&gt;While creating an auto-scaling group, could be the need to map each of the
instances to use an Elastic IP&#39;s, based on the scaling in/out policies
this would imply that after reaching the 100 limit, each reboot will cost
&lt;strong&gt;$0.10&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id=&quot;example-of-how-to-use-the-associate-address-from-a-startup-script&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#example-of-how-to-use-the-associate-address-from-a-startup-script&quot; aria-label=&quot;Anchor link for: example-of-how-to-use-the-associate-address-from-a-startup-script&quot;&gt;🔗&lt;/a&gt;Example of how to use the &lt;code&gt;associate-address&lt;/code&gt; from a startup script&lt;/h1&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;# KEYWORD: firstboot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;# PROVIDE: set_hostname&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;# REQUIRE: NETWORKING&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;# BEFORE:  SERVERS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; /etc/rc.subr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;name&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;set_hostname&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rcvar&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;set_hostname_enable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;start_cmd&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;set_hostname_run&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;stop_cmd&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-8&quot;&gt;export&lt;/span&gt;&lt;span&gt; AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&lt;/span&gt;&lt;span&gt;aws_access_key_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-8&quot;&gt;export&lt;/span&gt;&lt;span&gt; AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&lt;/span&gt;&lt;span&gt;aws_secret_access_key&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-8&quot;&gt;export&lt;/span&gt;&lt;span&gt; AWS_DEFAULT_REGION&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&lt;/span&gt;&lt;span&gt;the_region&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TAG_NAME&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;Salt&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=$(&lt;/span&gt;&lt;span class=&quot;z-12&quot;&gt;/usr/local/bin/curl&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; -s http://169.254.169.254/latest/meta-data/instance-id&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;REGION&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=$(&lt;/span&gt;&lt;span class=&quot;z-12&quot;&gt;/usr/local/bin/curl&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; -s http://169.254.169.254/latest/meta-data/placement/availability-zone&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-12&quot;&gt; sed&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;s/.$//&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;#39;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TAG_VALUE&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;=$(&lt;/span&gt;&lt;span class=&quot;z-12&quot;&gt;/usr/local/bin/aws&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; ec2 describe-tags --filters&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;Name=resource-id,Values=&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;${&lt;/span&gt;&lt;span&gt;INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&amp;quot; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;Name=key,Values=&lt;/span&gt;&lt;span&gt;$TAG_NAME&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; --region&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; ${&lt;/span&gt;&lt;span&gt;REGION&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; --output=text&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; |&lt;/span&gt;&lt;span class=&quot;z-12&quot;&gt; cut&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; -f5&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-2&quot;&gt;set_hostname_run&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;	hostname&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; ${&lt;/span&gt;&lt;span&gt;INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;	sysrc&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; hostname=&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;${&lt;/span&gt;&lt;span&gt;INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;	sysrc&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; salt_minion_enable=&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;YES&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-2&quot;&gt;	echo&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; ${&lt;/span&gt;&lt;span&gt;INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;} &amp;gt;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; /usr/local/etc/salt/minion_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;	pw&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; usermod root -c&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;root on &lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;${&lt;/span&gt;&lt;span&gt;INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;	if&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; [ ! -z &amp;quot;${&lt;/span&gt;&lt;span&gt;TAG_VALUE&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&amp;quot; ];&lt;/span&gt;&lt;span class=&quot;z-3 z-i&quot;&gt; then&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-2&quot;&gt;		echo&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;node_type: &lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;${&lt;/span&gt;&lt;span&gt;TAG_VALUE&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;}&amp;quot; &amp;gt;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; /usr/local/etc/salt/grains&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;	fi&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;	# allocate IP X.X.X.X&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;	/usr/local/bin/aws&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; ec2 associate-address --instance-id&lt;/span&gt;&lt;span&gt; $INSTANCE_ID&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; --allocation-id eipalloc-xxxxxxxx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;load_rc_config&lt;/span&gt;&lt;span&gt; $name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;run_rc_command&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot; z-i&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</content>
        
    </entry>
</feed>
