이 질문에 대한 대답은 튜토리얼에 대한 충분한 밀도이다. 지금은 적절한 포럼과 스레드에 복사하여 붙여 넣어 단어를 알아냅니다.
불평하지 않고, 나는 카멜이 얼마나 강력한 지, 설명서 및 예제 기반이 무엇인지 말할 수 있습니다. 정말 AWS의 세계에서 생산 시나리오 부족 ... 한숨은 ...는 오픈 소스 LIB의 입 아마 스트레칭을 이잖아.
camel-s3 documentation 공식을 참조하여 자격 증명 문제를 해결하는 방법을 알아 냈습니다. 고급 S3 구성을 만드는 방법을 먼저 보도록하겠습니다. (aws sdk 자체에 의존합니다. s3 클라이언트를 수동으로). 나는이 알아 낸 후 , 나는 내가 클라이언트 자체를 구축 할 수 있어요 때문에 이것이 EC2 인스턴스에서 일할 수있는 방법을 알아 내기 위해 aws sdk documentation on IAM credentials에게 갔다. 앞서 언급 한 문서에는 몇 가지 베어 본 예제가 있습니다. 나열된 예제로 테스트를 테스트하자마자 자격 증명 새로 고침 (이 질문의 유일한 목적)이 작동하지 않는 것으로 나타났습니다. 처음에는 자격 증명을 얻을 수 있었지만 수동으로 만료 된 후에는 테스트 중에 다시 채워지지 않았습니다. 마지막으로 자격 증명의 새로 고침을 처리 할 수있는 공급자 체인을 지정할 수 있다고 생각했습니다. 이것을 설명하는 aws 문서는 here입니다.
결국 aws s3 버킷을 폴링하는 내 로컬 낙타 설정에 대한 정적 자격 증명이 필요하지만 ec2s에 살고있는 원격 환경은 스스로를 완벽하게 새로 고치는 임시 자격 증명으로 액세스 할 수 있습니다. 와우 사! :)
이 작업을 수행하려면, 난 그저 내 로컬 개발 및 임시 IAM 자격 증명에 의존하는 원격 낙타 설정에 로컬 낙타 설정을 사용하는 공장을 만들었다. 이렇게하면 보안 우려와 모든 원격 환경에 대한 자격 증명을 수동으로 새로 고쳐야하는 작업을 줄일 수 있습니다!
팩토리를 만드는 방법이나 내 로컬 & 원격 구성이 어떻게 설정되었는지는 설명하지 않지만 원격 설정을 위해 S3 클라이언트를 만드는 AmazonS3ClientBuilder의 코드 샘플을 포함합니다.
AmazonS3ClientBuilder.standard()
.withCredentials(new InstanceProfileCredentialsProvider(false))
.withRegion(Regions.US_WEST_2)
.build();
내가 어떻게 작동하는지 알고 싶다면 전체 프로세스를 보여주는 예제 프로젝트를 제공 할 수 있습니다. 요청에 의해
, 여기 S3 클라이언트 내 로컬 및 원격 구현은 다음과 같습니다 지역 :
public class LocalAWSS3ClientManagerImpl implements AWSS3ClientManager {
private static Logger logger = LoggerFactory.getLogger(LocalAWSS3ClientManagerImpl.class);
private PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties;
private SimpleRegistry registry = new SimpleRegistry();
private CamelContext camelContext;
public LocalAWSS3ClientManagerImpl(PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties) {
this.priorityCodeSourcesRoutesProperties = priorityCodeSourcesRoutesProperties;
registry.put("amazonS3Client", getS3Client());
camelContext = new DefaultCamelContext(registry);
logger.info("Creating an AWS S3 manager for a local instance (you should not see this on AWS EC2s).");
}
private AmazonS3 getS3Client() {
try {
String awsBucketAccessKey = priorityCodeSourcesRoutesProperties.getAwsBucketAccessKey();
String awsBucketSecretKey = priorityCodeSourcesRoutesProperties.getAwsBucketSecretKey();
AWSCredentials awsCredentials = new BasicAWSCredentials(awsBucketAccessKey, awsBucketSecretKey);
return AmazonS3ClientBuilder.standard().withCredentials(
new AWSStaticCredentialsProvider(awsCredentials)).build();
} catch (RuntimeException ex) {
logger.error("Could not create AWS S3 client with the given credentials from the local config.");
}
return null;
}
public Endpoint getIncomingAWSEndpoint(final String incomingAWSBucket, final String region,
final String fileNameToSaveAndDownload) {
return camelContext.getEndpoint(
"aws-s3://" + incomingAWSBucket + "?" + "amazonS3Client=#amazonS3Client"
+ "®ion=" + region + "&deleteAfterRead=false" + "&prefix=" + fileNameToSaveAndDownload);
}
public Endpoint getOutgoingLocalEndpoint(final String outgoingEndpointDirectory,
final String fileNameToSaveAndDownload) {
return camelContext.getEndpoint(
"file://" + outgoingEndpointDirectory + "?" + "fileName="
+ fileNameToSaveAndDownload + "&readLock=markerFile");
}
}
원격 :
public class RemoteAWSS3ClientManagerImpl implements AWSS3ClientManager {
private static Logger logger = LoggerFactory.getLogger(RemoteAWSS3ClientManagerImpl.class);
private PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties;
private SimpleRegistry registry = new SimpleRegistry();
private CamelContext camelContext;
public RemoteAWSS3ClientManagerImpl(PriorityCodeSourcesRoutesProperties priorityCodeSourcesRoutesProperties) {
this.priorityCodeSourcesRoutesProperties = priorityCodeSourcesRoutesProperties;
registry.put("amazonS3Client", getS3Client());
camelContext = new DefaultCamelContext(registry);
logger.info("Creating an AWS S3 client for a remote instance (normal for ec2s).");
}
private AmazonS3 getS3Client() {
try {
logger.info("Attempting to create an AWS S3 client with IAM role's temporary credentials.");
return AmazonS3ClientBuilder.standard()
.withCredentials(new InstanceProfileCredentialsProvider(false))
.withRegion(Regions.US_WEST_2)
.build();
} catch (RuntimeException ex) {
logger.error("Could not create AWS S3 client with the given credentials from the instance. "
+ "The default credential chain was used to create the AWS S3 client. "
+ ex.toString());
}
return null;
}
public Endpoint getIncomingAWSEndpoint(final String incomingAWSBucket, final String region,
final String fileNameToSaveAndDownload) {
return camelContext.getEndpoint(
"aws-s3://" + incomingAWSBucket + "?" + "amazonS3Client=#amazonS3Client"
+ "®ion=" + region + "&deleteAfterRead=false" + "&prefix=" + fileNameToSaveAndDownload);
}
public Endpoint getOutgoingLocalEndpoint(final String outgoingEndpointDirectory,
final String fileNameToSaveAndDownload) {
return camelContext.getEndpoint(
"file://" + outgoingEndpointDirectory + "?" + "fileName="
+ fileNameToSaveAndDownload + "&readLock=markerFile");
}
}
당신은 낙타 버전이 사용합니까, 더 말해, 수 그 경로에서 끝점을 사용합니까? 또는 무엇을합니까? 그리고 만료 된 자격 증명의 경우 수행하려는 작업 –
Camel 버전 2.20.0, AWS s3을 가리키는 하나의 경로가 있고 "to"경로가 로컬 디렉토리입니다. 마지막으로, 자격 증명이 더 이상 작동하지 않으면 (기본적으로 시간 초과 예외) 낙타에 예외를 던지 려합니다. –
아직 증명할 필요는 없지만 낙타 프로세스 내에서 AWS의 기본 자격 증명 체인에 의존하는 맞춤 S3 클라이언트를 사용하면 자격 증명 자체를 관리하는 클라이언트가 생성되는 것 같습니다. 실험을 마칠 때 이것을 업데이트 할 것입니다 : AmazonS3ClientBuilder.standard(). withRegion (Regions.US_WEST_2) .build(); –