Java tutorial
/* * Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Amazon Software License (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/asl/ * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.calamp.services.kinesis.events.utils; import com.amazonaws.AmazonClientException; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.profile.ProfileCredentialsProvider; /** * Provides utilities for retrieving credentials to talk to AWS */ public class CredentialUtils { public static AWSCredentialsProvider getCredentialsProvider() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential profile by * reading from the credentials file located at (~/.aws/credentials). */ AWSCredentialsProvider credentialsProvider = null; try { credentialsProvider = new ProfileCredentialsProvider("default"); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } return credentialsProvider; } }