Example usage for com.amazonaws.services.lambda AWSLambda listFunctions

List of usage examples for com.amazonaws.services.lambda AWSLambda listFunctions

Introduction

In this page you can find the example usage for com.amazonaws.services.lambda AWSLambda listFunctions.

Prototype

ListFunctionsResult listFunctions(ListFunctionsRequest listFunctionsRequest);

Source Link

Document

Returns a list of Lambda functions, with the version-specific configuration of each.

Usage

From source file:com.netflix.spinnaker.clouddriver.lambda.provider.agent.LambdaCachingAgent.java

License:Apache License

@Override
public CacheResult loadData(ProviderCache providerCache) {
    log.info("Describing items in {}", getAgentType());

    AWSLambda lambda = amazonClientProvider.getAmazonLambda(account, region);
    String nextMarker = null;//from ww w .j a v  a 2 s  .  c  o  m
    List<FunctionConfiguration> lstFunction = new ArrayList<FunctionConfiguration>();

    do {
        ListFunctionsRequest listFunctionsRequest = new ListFunctionsRequest();
        if (nextMarker != null) {
            listFunctionsRequest.setMarker(nextMarker);
        }

        ListFunctionsResult listFunctionsResult = lambda.listFunctions(listFunctionsRequest);
        lstFunction.addAll(listFunctionsResult.getFunctions());
        nextMarker = listFunctionsResult.getNextMarker();

    } while (nextMarker != null && nextMarker.length() != 0);

    Collection<CacheData> data = new LinkedList<>();
    for (FunctionConfiguration x : lstFunction) {
        Map<String, Object> attributes = objectMapper.convertValue(x, ATTRIBUTES);
        attributes.put("account", account.getName());
        attributes.put("region", region);

        attributes.put("revisions", listFunctionRevisions(x.getFunctionArn()));
        attributes.put("aliasConfiguration", listAliasConfiguration(x.getFunctionArn()));
        attributes.put("eventSourceMappings", listEventSourceMappingConfiguration(x.getFunctionArn()));

        data.add(new DefaultCacheData(Keys.getLambdaFunctionKey(account.getName(), region, x.getFunctionName()),
                attributes, Collections.emptyMap()));
    }

    log.info("Caching {} items in {}", String.valueOf(data.size()), getAgentType());
    return new DefaultCacheResult(Collections.singletonMap(LAMBDA_FUNCTIONS.ns, data));
}