use of com.amazonaws.services.lambda.model.FunctionConfiguration in project aws-doc-sdk-examples by awsdocs.
the class ListFunctions method main.
public static void main(String[] args) {
// snippet-start:[lambda.java1.list.main]
ListFunctionsResult functionResult = null;
try {
AWSLambda awsLambda = AWSLambdaClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(Regions.US_WEST_2).build();
functionResult = awsLambda.listFunctions();
List<FunctionConfiguration> list = functionResult.getFunctions();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
FunctionConfiguration config = (FunctionConfiguration) iter.next();
System.out.println("The function name is " + config.getFunctionName());
}
} catch (ServiceException e) {
System.out.println(e);
}
// snippet-end:[lambda.java1.list.main]
}
use of com.amazonaws.services.lambda.model.FunctionConfiguration in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAmazonResourceNamesOfAPI.
// AWS Lambda: rest api operation to get ARNs
@Override
public Response getAmazonResourceNamesOfAPI(String apiId, MessageContext messageContext) {
JSONObject arns = new JSONObject();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
API api = apiProvider.getAPIbyUUID(apiId, organization);
String endpointConfigString = api.getEndpointConfig();
if (!StringUtils.isEmpty(endpointConfigString)) {
JSONParser jsonParser = new JSONParser();
JSONObject endpointConfig = (JSONObject) jsonParser.parse(endpointConfigString);
if (endpointConfig != null) {
if (endpointConfig.containsKey(APIConstants.AMZN_ACCESS_KEY) && endpointConfig.containsKey(APIConstants.AMZN_SECRET_KEY) && endpointConfig.containsKey(APIConstants.AMZN_REGION)) {
String accessKey = (String) endpointConfig.get(APIConstants.AMZN_ACCESS_KEY);
String secretKey = (String) endpointConfig.get(APIConstants.AMZN_SECRET_KEY);
String region = (String) endpointConfig.get(APIConstants.AMZN_REGION);
AWSCredentialsProvider credentialsProvider;
AWSLambda awsLambda;
if (StringUtils.isEmpty(accessKey) && StringUtils.isEmpty(secretKey) && StringUtils.isEmpty(region)) {
credentialsProvider = DefaultAWSCredentialsProviderChain.getInstance();
awsLambda = AWSLambdaClientBuilder.standard().withCredentials(credentialsProvider).build();
} else if (!StringUtils.isEmpty(accessKey) && !StringUtils.isEmpty(secretKey) && !StringUtils.isEmpty(region)) {
if (secretKey.length() == APIConstants.AWS_ENCRYPTED_SECRET_KEY_LENGTH) {
CryptoUtil cryptoUtil = CryptoUtil.getDefaultCryptoUtil();
secretKey = new String(cryptoUtil.base64DecodeAndDecrypt(secretKey), APIConstants.DigestAuthConstants.CHARSET);
}
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
credentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
awsLambda = AWSLambdaClientBuilder.standard().withCredentials(credentialsProvider).withRegion(region).build();
} else {
log.error("Missing AWS Credentials");
return null;
}
ListFunctionsResult listFunctionsResult = awsLambda.listFunctions();
List<FunctionConfiguration> functionConfigurations = listFunctionsResult.getFunctions();
arns.put("count", functionConfigurations.size());
JSONArray list = new JSONArray();
for (FunctionConfiguration functionConfiguration : functionConfigurations) {
list.put(functionConfiguration.getFunctionArn());
}
arns.put("list", list);
return Response.ok().entity(arns.toString()).build();
}
}
}
} catch (SdkClientException e) {
if (e.getCause() instanceof UnknownHostException) {
arns.put("error", "No internet connection to connect the given access method.");
log.error("No internet connection to connect the given access method of API : " + apiId, e);
return Response.serverError().entity(arns.toString()).build();
} else {
arns.put("error", "Unable to access Lambda functions under the given access method.");
log.error("Unable to access Lambda functions under the given access method of API : " + apiId, e);
return Response.serverError().entity(arns.toString()).build();
}
} catch (ParseException e) {
String errorMessage = "Error while parsing endpoint config of the API: " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (CryptoException | UnsupportedEncodingException e) {
String errorMessage = "Error while decrypting the secret key of the API: " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving the API: " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations