I have an ALB that has lambda as target group. Essentially, the lambda that does logic checks and returns a response:
{
'statusCode': 301,
'headers': {
'Location': url,
},
'body': null,
'isBase64Encoded': false
}
The response above will return a 502 bad gateway, which doesn't really help with debugging the issue. Cloudwatch says it returns the response above. The logic before the response works just fine. I would test with a status code 200, content-type application/json and a debugging message, which would return properly to the user. I know ALB has a listener for redirects, but the lambda has to go through logic to properly redirect someone first which requires things from secret manager. So the question stands, are there any other ways to redirect with alb using lambda? I tried searching through documentaries to see if there are any other limitations with lambdas as a target group. Other than the 1 mb payload/request and formatting response payload, I haven't seen anything of notice.
CodePudding user response:
Sadly no. It's not lambdas role in alb to perform any redirections. If you use CloudFront, you can use lambda functions in your distribution to do redirections instead.