By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How do I use the AWS CLI to register a Lambda function as a target behind my Application Load Balancer?

2 minute read
0

I want to register an AWS Lambda function as a target behind my Application Load Balancer. To complete this action, I want to use the AWS Command Line Interface (AWS CLI).

Resolution

Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

  1. To create a target group with the target type set to Lambda, run the create-target-group command. Replace [your target group's name] with the name of your target:

    aws elbv2 create-target-group \    --name [your target group's name] \
        --target-type lambda
  2. To allow Elastic Load Balancing (ELB) to invoke your Lambda function, run the add-permission command. Replace [your Lambda function's name] and [your target group's ARN] with your respective names:

    aws lambda add-permission \    --function-name [your Lambda function's name] \
        --statement-id load-balancer \
        --principal elasticloadbalancing.amazonaws.com \
        --action lambda:InvokeFunction \
        --source-arn [your target group's ARN]
  3. To register Lambda as the target, run the register-targets command. Replace [your target group's ARN] and [your Lambda function's ARN] with your information:

    aws elbv2 register-targets \     --target-group-arn [your target group's ARN] \ 
        --targets Id=[your Lambda function's ARN]
AWS OFFICIAL
AWS OFFICIALUpdated 3 months ago