2017-09-29 13 views
0

私はElasticacheのredisインスタンスに接続する必要があります。私がAmazon Elasticache Redis cluster - Can't get Endpointから理解しているように、私はこれからエンドポイントを得ることができます。 ここでエンドポイントを取得し、このエンドポイントを使用してJedisClientを作成するとします(私はJavaを使用しているため)。次にAWS IAM資格情報をどのように提供しますか? IAMポリシーを使用してElastiCacheを保護します。このレディスに他のアプリケーションが接続しないようにするにはどうすればよいですか?AWS Elasticache Jedisが資格情報を使用しています

答えて

0
static AWSCredentials credentials = null; 
static { 
    try { 
     //credentials = new ProfileCredentialsProvider("default").getCredentials(); 
     credentials = new SystemPropertiesCredentialsProvider().getCredentials(); 
    } catch (Exception e) { 
     System.out.println("Got exception.........."); 
     throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " 
       + "Please make sure that your credentials file is at the correct " 
       + "location (/Users/USERNAME/.aws/credentials), and is in valid format.", e); 
    }  
} 

@Bean 
public LettuceConnectionFactory redisConnectionFactory() { 
    AmazonElastiCache elasticacheClient = AmazonElastiCacheClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_1).build(); 
    DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest(); 
    dccRequest.setShowCacheNodeInfo(true); 

    DescribeCacheClustersResult clusterResult = elasticacheClient.describeCacheClusters(dccRequest); 

    List<CacheCluster> cacheClusters = clusterResult.getCacheClusters(); 
    List<String> clusterNodes = new ArrayList <String>(); 
    try { 
     for (CacheCluster cacheCluster : cacheClusters) { 
      for (CacheNode cacheNode : cacheCluster.getCacheNodes()) { 
       String addr = cacheNode.getEndpoint().getAddress(); 
       int port = cacheNode.getEndpoint().getPort(); 
       String url = addr + ":" + port; 
       if(<ReplicationGroup Name>.equalsIgnoreCase(cacheCluster.getReplicationGroupId())) 
        clusterNodes.add(url); 
      } 
     } 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    }  
    LettuceConnectionFactory redisConnectionFactory = new LettuceConnectionFactory(new RedisClusterConfiguration(clusterNodes)); 
    redisConnectionFactory.setUseSsl(true); 
    redisConnectionFactory.afterPropertiesSet(); 
    return redisConnectionFactory; 
} 
関連する問題