0
votes

I'm trying to retrieve apigateway name in my Lambda code. I'v referred the following document on AWS http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html.

I understand that we can retrieve the API ID using the context variable. However I'm interested in retrieving the actual name of the API which was created. Is there any way of getting it?

Thanks in advance.

2

2 Answers

1
votes

To my knowledge, you can't get the API Gateway name directly, but you can get the API Gateway Id.

Both an event and context are passed in. In the event, there is a key called "requestContext". Inside the request context is the "apiId" key.

You could then use the API key id to look up the name if needed.

0
votes

Unfortunately you will not be able to get API name directly from context, you will only get its identifier.

One way to get this information is to get your API information based on your ID from context:

response = client.get_rest_api(
    restApiId='string'
)

You will then receive this response:

{
    'id': 'string',
    'name': 'string',
    'description': 'string',
    'createdDate': datetime(2015, 1, 1),
    'version': 'string',
    'warnings': [
        'string',
    ],
    'binaryMediaTypes': [
        'string',
    ],
    'minimumCompressionSize': 123,
    'apiKeySource': 'HEADER'|'AUTHORIZER',
    'endpointConfiguration': {
        'types': [
            'REGIONAL'|'EDGE'|'PRIVATE',
        ]
    },
    'policy': 'string'
}

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client.get_rest_api