Geeky hackling
Geeky hackling

Reputation: 1

How to get the name of the api gateway invoking aws lambda using java

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.

Upvotes: 0

Views: 1112

Answers (2)

Steve HOUEL
Steve HOUEL

Reputation: 197

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

Upvotes: 0

Jason Tyler
Jason Tyler

Reputation: 101

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.

Upvotes: 1

Related Questions