title: How to programmatically register a lambda listener rule to an ALB?
body: <p>Given that ALB Lambda integration is not currently supported by Cloudformation, I am trying to write a simple script to create a target group, register the lambda to the target group and then point a listener rule to that target group.</p>
  
  <p>This works when I do it by the user interface however my attempts to register the lambda target to the target group fail (both in python script and cli):</p>
  
  <pre><code>botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the RegisterTargets operation: elasticloadbalancing principal does not have permission to invoke &lt;LAMBDA ARN&gt; from target group &lt;TARGET GROUP ARN&gt;
  </code></pre>
  
  <p>Below is the python script which does this:</p>
  
  <pre><code>import boto3
  import os
  
  environment = os.environ['ENV']
  cloudformation = boto3.resource('cloudformation')
  elb = boto3.client('elbv2')
  
  stack = cloudformation.Stack('boomerang')
  
  output = [x for x in stack.outputs if x['ExportName'] == 'boomerang-beacon-lambda'][0]
  beacon_arn = output['OutputValue']
  
  response = elb.create_target_group(
    TargetType='lambda',
    Name='public-%s-boomerang-beacon' % environment
  )
  
  target_group_arn = response['TargetGroups'][0]['TargetGroupArn']
  
  elb.register_targets(
    TargetGroupArn=target_group_arn,
    Targets=[
      {
        'Id': beacon_arn
      },
    ]
  )
  </code></pre>
  
  <p>Thank you</p>