-
Notifications
You must be signed in to change notification settings - Fork 171
Customization
g9yuayon edited this page Dec 9, 2013
·
3 revisions
###Setting up AWS Credentials
To use S3FileSink or SQSNotice, we need to specify AWS credentials for Suro server. For the security reason, if we do not want to write AWS secret key and access key on configuration file, we can set up custom AWS credential implementing com.amazonaws.auth.AWSCredentialProvider
by extending Guice module. For example, a SuroModule
that initializes PropertyAWSCredentialProvider is used with the following code
public class SuroModule extends AbstractModule {
private final Properties properties;
public SuroModule(Properties properties) {
this.properties = properties;
}
@Override
protected void configure() {
bind(AWSCredentialsProvider.class)
.annotatedWith(Names.named("credentials")).to(PropertyAWSCredentialsProvider.class);
bind(ObjectMapper.class).to(DefaultObjectMapper.class).asEagerSingleton();
bind(AWSCredentialsProvider.class).to(PropertyAWSCredentialsProvider.class);
bind(SinkManager.class);
bind(RoutingMap.class);
bind(SuroService.class);
bind(StatusServer.class);
}
}
public class PropertyAWSCredentialsProvider implements AWSCredentialsProvider {
@Configuration("SuroServer.AWSAccessKey")
private String accessKey;
@Configuration("SuroServer.AWSSecretKey")
private String secretKey;
@Override
public AWSCredentials getCredentials() {
if (accessKey != null && secretKey != null) {
return new AWSCredentials() {
@Override
public String getAWSAccessKeyId() {
return accessKey;
}
@Override
public String getAWSSecretKey() {
return secretKey;
}
};
}
else {
return null;
}
}
@Override
public void refresh() {
}
}
To customize AWSCredentialProvider, try the following sample:
bind(AWSCredentialsProvider.class)
.annotatedWith(Names.named("credentials")).to(NFAWSCredentialProvider.class);
...
public class NFAWSCredentialProvider implements AWSCredentialsProvider {
private final AWSManager awsManager;
@Inject
public NFAWSCredentialProvider(AWSManager awsManager) {
this.awsManager = awsManager;
}
@Override
public AWSCredentials getCredentials() {
// return whatever you want
}
@Override
public void refresh() {
// do refresh
}
}