Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get alias name of AWS Lambda function in code

I implement AWS Lambda function on Java using AWS Java SDK and AWS Lambda Java Support Libraries and in some cases I need to get name, version and alias of current function right in code of the function.

Name and version I can get from Context using getFunctionName() and getFunctionVersion() methods. But how can I get current alias value?

like image 442
Gleb Avatar asked May 03 '18 11:05

Gleb


People also ask

What is AWS Lambda function alias?

A Lambda alias is like a pointer to a specific function version. Users can access the function version using the alias Amazon Resource Name (ARN). Sections. Creating a function alias (Console) Managing aliases with the Lambda API.

How do I find the lambda function code?

When you're downloading the source code for a lambda function, check whether the function has layers. To see if a lambda function has layers, click on the Code tab on the function's page and scroll down until you see the Layers section. If your function has layers, you have to download the layer code as well.

How do I find my AWS Lambda ID?

Finding your AWS account ID You must be signed in to the AWS Management Console. For more information, see Signing in to the AWS Management Console in the IAM User Guide. In the navigation bar on the upper right, choose your account name or number and then choose My Security Credentials.


1 Answers

You can use the Context object passed into the lambda handler to get that data. https://docs.aws.amazon.com/lambda/latest/dg/java-context-object.html

The context object properties are:

getMemoryLimitInMB(): Memory limit, in MB, you configured for the Lambda function.

getFunctionName(): Name of the Lambda function that is running.

getFunctionVersion(): The Lambda function version that is executing. If an alias is used to invoke the function, then getFunctionVersion will be the version the alias points to.

getInvokedFunctionArn(): The ARN used to invoke this function. It can be function ARN or alias ARN. An unqualified ARN executes the $LATEST version and aliases execute the function version it is pointing to.

like image 170
Yogesh_D Avatar answered Sep 21 '22 11:09

Yogesh_D