How to get the name of the stage in which my lambda function is running?
For Lambda Proxy integration, you can get the stage name from the requestContext in the input stream, which contains the API request serialized as a JSON string by API Gateway. The input data can also include the request's stage variables stageVariables (if you use/need any). For example:
JSONParser parser = new JSONParser();
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
...
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String stage = null;
JSONObject event = (JSONObject)parser.parse(reader);
if (event.get("requestContext") != null) {
JSONObject requestContext = (JSONObject)parser.parse((String)event.get("requestContext"));
if (requestContext.get("stage") != null) {
stage = (String)requestContext.get("stage");
}
}
...
}
See full example.
What does this default region means? will it be always same as the region in which my lambda function is running?
YES according to docs and NO according to the SDK.
The SDK does not reference it. It uses AWS_REGION only. See SDKGlobalConfiguration.java.