To get the AWS Region where your Lambda Function is running we need to access the Environment Variable AWS_REGION
.
To access the environment variable AWS_REGION
using Node.js Lambda Function we can use process.env.AWS_REGION
.
To get the AWS Region where your Lambda Function is running we need to access the Environment Variable AWS_REGION
.
To access the environment variable AWS_REGION
using Node.js Lambda Function we can use process.env.AWS_REGION
.
To get the AWS Account ID of the currently running Lambda Function using Node.js use the code below.
exports.handler = async (event, context) => {
const awsAccountId = context.invokedFunctionArn.split(':')[4]
console.log(awsAccountId)
};
Continue reading How to get the AWS Account ID in Lambda Node.js AWS Lambda Environment Variables are a useful way to input configuration values to your AWS Lambda runtime. Especially, when there are configurations that are different in your Development environment compared to your Production environment. Like name of DynamoDB tables or MySQL databases.
Below we discuss how we can retrieve the values of Environment Variables in AWS Lambda using Ruby.
The code for accessing Environment Variables on AWS Lambda is just the same code for accessing environment variables in your local computer or server.
Here is the code to access environment variables using Ruby.
env_var = ENV['ENVIRONMENT_VARIABLE']
If we want to get the value of an environment variable with the key of DB_HOST
then we will use the code below.
If you want to get the AWS Account ID of your Lambda Function while it is running then you can use the code below. The code below is written in Ruby.
Continue reading How to get AWS Account ID in Lambda using RubyIf you need to get the Region of your running Lambda Function then you should look for the AWS_REGION
in the Environment Variables.
Below is the code on how to access the AWS_REGION
Environment Variable using Ruby.
aws_region = ENV['AWS_REGION']
Continue reading How to get the Region of a Running AWS Lambda Function using Ruby To get the remaining time of a running AWS Lambda Function using Python you should check the context
object and its get_remaining_time_in_millis
function.
To get the remaining time of a running Lambda Function using Node.js, we will use the context
object’s getRemainingTimeInMillis()
function. This returns the number of milliseconds that the Lambda Function can still run before it times out.
Below is a simple code that fetches the remaining time inside a Lambda Function. I have set the timeout to be only 3 seconds, that is why the output is 2,999 milliseconds or approximately 3 seconds.
Continue reading How to get the remaining time of a running AWS Lambda Function using Node.jsIf you want to list the files/objects inside a specific folder within an S3 bucket then you will need to use the list_objects_v2
method with the Prefix
parameter in boto3.
Below are 3 examples codes on how to list the objects in an S3 bucket folder.
What the code does is that it gets all the files/objects inside the S3 bucket named radishlogic-bucket within the folder named s3_folder/ and adds their keys inside a Python list (s3_object_key_list
). It then prints each of the object keys in the list and also prints the number of files in the folder.
If you need to list all files/objects inside an AWS S3 Bucket then you will need to use the list_objects_v2 method in boto3.
Below are 3 example codes of how to list all files in a target S3 Bucket.
You can use any of the 3 options since it does the same thing.
It will get all of the files inside the S3 Bucket radishlogic-bucket using Python boto3, put it inside a Python list, then print each object key. It will print the files inside folder recursively, regardless if they are inside a folder or not.
At the end, it will also print the number of items inside the S3 Bucket.
Continue reading How to list all objects in an S3 Bucket using boto3 and PythonTo delete a file inside an AWS S3 Bucket using Python then you will need to use the delete_object function of boto3.
Below are 3 examples to delete an S3 file.
You can use any of the 3 options since it does the same thing. It will delete the file in S3 with the key of s3_folder/file.txt inside the S3 bucket named radishlogic-bucket using Python boto3.
Continue reading How to delete a file in AWS S3 using boto3 and Python