[PYTHON] Try giving AWS Lambda environment variables?

I have created a production environment and a test environment in different regions, but there are cases where I want to make different operations depending on the environment, such as when accessing outside AWS. I'm basically using API Gateway


      x-amazon-apigateway-integration:
        type: HTTP
        uri: https://example.com
        httpMethod: GET
        requestParameters:
          integration.request.header.hoge: "'some value'"

I'm dealing with it by dividing yaml by region, but it's not smart because similar yaml is managed twice in the repository. .. I was happy if AWS Lambda had environment variables, but I learned a deprecated trick at a study session.


print(context.function_name)

~~ Write parameters in the function name and pass it, then ...? ~~

~~ When I was taught, I heard "I can write JSON in the description!", And I checked if it was acceptable, but I couldn't find a way to get the description. Since the parameter is written in the function name with its own parser or the death flag is too much, I will obediently wait for the version upgrade of AWS Lambda, ~~

It was getFunctionConfiguration properly!

https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/API_GetFunctionConfiguration.html http://boto3.readthedocs.org/en/latest/reference/services/lambda.html#Lambda.Client.get_function_configuration

I misunderstood what the context object has. This will widen the width ^ ^

import boto3

def lambda_handler(event, context):
    client = boto3.client('lambda')
    response = client.get_function_configuration(
        FunctionName=context.function_name
    )
    print(response['Description'])

Recommended Posts

Try giving AWS Lambda environment variables?
Try AWS Lambda Destinations
Touch AWS Lambda environment variable support
Environment when AWS Lambda includes native libraries
Shell variables, environment variables
[AWS] Try tracing API Gateway + Lambda with X-Ray
[Python] Get environment variables
What are environment variables?
I tried running TensorFlow in AWS Lambda environment: Preparation
Tweet from AWS Lambda
[AWS] Try adding Python library to Layer with SAM + Lambda (Python)
Try automating Start / Stop for EC2 instances with AWS Lambda
I just built a virtual environment with AWS lambda layer
Environment variables when using Tkinter
Handle Go environment variables (viper)
[Python] Scraping in AWS Lambda
The simplest AWS Lambda implementation
What are environment variables? (Linux)
Handle environment variables in Python
HTTP environment variables in Flask
Try using AWS SageMaker Studio
AWS Lambda with PyTorch [Lambda import]
Web scraping using AWS lambda
Set environment variables with lambda-uploader
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
Prepare an environment to use OpenCV and Pillow with AWS Lambda
Install pip in Serverless Framework and AWS Lambda with Python environment