Search in sources :

Example 1 with AWSSimpleSystemsManagement

use of com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement in project aws-java-serverless by hermanlintvelt.

the class SecureParameterService method getParameterValue.

public static String getParameterValue(String name, boolean withDecryption) {
    final AWSSimpleSystemsManagement client = AWSSimpleSystemsManagementClientBuilder.defaultClient();
    GetParameterRequest request = new GetParameterRequest();
    request.withName(name).setWithDecryption(withDecryption);
    GetParameterResult result = client.getParameter(request);
    LOG.debug("SSM result for param " + name + ": " + result);
    if (result.getParameter() != null) {
        return result.getParameter().getValue();
    } else {
        return null;
    }
}
Also used : GetParameterRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest) GetParameterResult(com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult) AWSSimpleSystemsManagement(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)

Example 2 with AWSSimpleSystemsManagement

use of com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement in project Gatekeeper by FINRAOS.

the class SsmService method executeSsm.

private Map<String, String> executeSsm(AWSEnvironment environment, List<String> instanceIds, String platform, Map<String, ArrayList<String>> parameters, GatekeeperSsmProperties.SsmDocument documentProperties) {
    AWSSimpleSystemsManagement ssmClient = awsSessionService.getSsmSession(environment);
    SendCommandRequest scr = new SendCommandRequest().withInstanceIds(instanceIds).withDocumentName(documentProperties.getDocumentName());
    for (String key : parameters.keySet()) {
        scr.addParametersEntry(key, parameters.get(key));
    }
    return waitForSsmCommand(ssmClient, ssmClient.sendCommand(scr).getCommand().getCommandId(), instanceIds.size(), documentProperties.getTimeout(), documentProperties.getWaitInterval());
}
Also used : AWSSimpleSystemsManagement(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)

Example 3 with AWSSimpleSystemsManagement

use of com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement in project Gatekeeper by FINRAOS.

the class SsmService method checkInstancesWithSsm.

public Map<String, String> checkInstancesWithSsm(AWSEnvironment environment, List<String> instanceIds) {
    Map<String, String> instanceStatuses = new HashMap<>();
    AWSSimpleSystemsManagement ssmClient = awsSessionService.getSsmSession(environment);
    for (int i = 0; i < instanceIds.size(); i += 50) {
        // since we're partitioning 50 at a time we need to make sure that we don't go over the index of the actual size of the set itself
        // if we do then we will use the upper value of the set.
        Integer upperBound = i + 50 < instanceIds.size() ? i + 50 : instanceIds.size();
        List<String> partitionedList = instanceIds.subList(i, upperBound);
        DescribeInstanceInformationRequest describeInstanceInformationRequest = new DescribeInstanceInformationRequest();
        InstanceInformationFilter filter = new InstanceInformationFilter();
        filter.setKey("InstanceIds");
        filter.setValueSet(partitionedList);
        List<InstanceInformationFilter> informationFilters = new ArrayList<>();
        informationFilters.add(filter);
        describeInstanceInformationRequest.setInstanceInformationFilterList(informationFilters);
        describeInstanceInformationRequest.setMaxResults(50);
        // make the initial call, SSM Chunks it up so we need to call it with tokens til the string returns empty.
        DescribeInstanceInformationResult describeInstanceInformationResult = ssmClient.describeInstanceInformation(describeInstanceInformationRequest);
        describeInstanceInformationResult.getInstanceInformationList().forEach(instance -> instanceStatuses.put(instance.getInstanceId(), instance.getPingStatus()));
        while (describeInstanceInformationResult.getNextToken() != null) {
            // get the next chunk of results
            describeInstanceInformationResult = ssmClient.describeInstanceInformation(describeInstanceInformationRequest.withNextToken(describeInstanceInformationResult.getNextToken()));
            describeInstanceInformationResult.getInstanceInformationList().forEach(instance -> instanceStatuses.put(instance.getInstanceId(), instance.getPingStatus()));
        }
    }
    return instanceStatuses;
}
Also used : AWSSimpleSystemsManagement(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)

Example 4 with AWSSimpleSystemsManagement

use of com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement in project spring-cloud-config by spring-cloud.

the class AwsParameterStoreEnvironmentRepositoryFactory method build.

@Override
public AwsParameterStoreEnvironmentRepository build(AwsParameterStoreEnvironmentProperties environmentProperties) {
    AWSSimpleSystemsManagementClientBuilder clientBuilder = AWSSimpleSystemsManagementClientBuilder.standard();
    configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
    AWSSimpleSystemsManagement client = clientBuilder.build();
    return new AwsParameterStoreEnvironmentRepository(client, configServerProperties, environmentProperties);
}
Also used : AWSSimpleSystemsManagementClientBuilder(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder) AWSSimpleSystemsManagement(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)

Example 5 with AWSSimpleSystemsManagement

use of com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement in project aws-doc-sdk-examples by awsdocs.

the class GetSimpleSystemsManagementOps method main.

public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Please specify a SSM OpsItem ID value. You can obtain this value using the AWS Console.");
        System.exit(1);
    }
    // snippet-start:[ssm.Java1.get_ops.main]
    // Get the OpsItem ID value
    String opsID = args[0];
    // Create the AWSSimpleSystemsManagement client object
    AWSSimpleSystemsManagement ssm = AWSSimpleSystemsManagementClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();
    try {
        GetOpsItemRequest opsRequest = new GetOpsItemRequest();
        opsRequest.setOpsItemId(opsID);
        GetOpsItemResult opsResults = ssm.getOpsItem(opsRequest);
        OpsItem item = opsResults.getOpsItem();
        System.out.println(item.getTitle());
        System.out.println(item.getDescription());
        System.out.println(item.getSource());
    } catch (AmazonServiceException e) {
        e.getStackTrace();
    }
// snippet-end:[ssm.Java1.get_ops.main]
}
Also used : GetOpsItemResult(com.amazonaws.services.simplesystemsmanagement.model.GetOpsItemResult) OpsItem(com.amazonaws.services.simplesystemsmanagement.model.OpsItem) AmazonServiceException(com.amazonaws.AmazonServiceException) AWSSimpleSystemsManagement(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement) GetOpsItemRequest(com.amazonaws.services.simplesystemsmanagement.model.GetOpsItemRequest)

Aggregations

AWSSimpleSystemsManagement (com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)9 AmazonServiceException (com.amazonaws.AmazonServiceException)2 AWSSimpleSystemsManagementClientBuilder (com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder)1 DescribeParametersRequest (com.amazonaws.services.simplesystemsmanagement.model.DescribeParametersRequest)1 DescribeParametersResult (com.amazonaws.services.simplesystemsmanagement.model.DescribeParametersResult)1 GetOpsItemRequest (com.amazonaws.services.simplesystemsmanagement.model.GetOpsItemRequest)1 GetOpsItemResult (com.amazonaws.services.simplesystemsmanagement.model.GetOpsItemResult)1 GetParameterRequest (com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest)1 GetParameterResult (com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult)1 OpsItem (com.amazonaws.services.simplesystemsmanagement.model.OpsItem)1 ParameterMetadata (com.amazonaws.services.simplesystemsmanagement.model.ParameterMetadata)1 AwsParamStorePropertySource (io.awspring.cloud.paramstore.AwsParamStorePropertySource)1 Test (org.junit.Test)1 ConfigData (org.springframework.boot.context.config.ConfigData)1 ConfigDataResourceNotFoundException (org.springframework.boot.context.config.ConfigDataResourceNotFoundException)1 CompositePropertySource (org.springframework.core.env.CompositePropertySource)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1