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