E, [2011-07-20T20:45:38.321580 #3504] ERROR -- : [AWS SNS 403 0.870669] publish {:message_structure=>"json", :topic_arn=>"arn:aws:sns:us-east-1:XXXXXXXXXXXX:XXXXXXXX", :message=>"{\"default\":\"デフォルトメッセージ\",\"email\":\"~\"}", :subject=>"Test"} AWS::SNS::Errors::SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
package com.dateofrock.android.test;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
import com.amazonaws.services.cloudwatch.model.Dimension;
import com.amazonaws.services.cloudwatch.model.MetricDatum;
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest;
import com.amazonaws.services.cloudwatch.model.StandardUnit;
import com.dateofrock.android.test.TwitterClient.APIResult;
public class CloudWatchClient {
public void sendMetrics(String twitterUser, APIResult result) {
if (result.isError()) {
return;
}
Dimension dimension = new Dimension().withValue(twitterUser).withName(
"User");
// リクエストの組み立て
PutMetricDataRequest request = new PutMetricDataRequest()
.withNamespace("Twitter").withMetricData(
new MetricDatum().withMetricName("Follower")
.withDimensions(dimension)
.withUnit(StandardUnit.Count.toString())
.withValue((double) result.followersCount),
new MetricDatum().withDimensions(dimension)
.withMetricName("Friends")
.withUnit(StandardUnit.Count.toString())
.withValue((double) result.friendsCount),
new MetricDatum().withDimensions(dimension)
.withMetricName("Status")
.withUnit(StandardUnit.Count.toString())
.withValue((double) result.statusCount)
);
// CloudWatchにデータ送信
AWSCredentials cred = new BasicAWSCredentials("アクセスキー", "シークレットキー");
AmazonCloudWatchClient client = new AmazonCloudWatchClient(cred);
client.setEndpoint(CloudWatchEndPoint.US_EAST);
client.putMetricData(request);
}
}
CloudWatchEndPoint.java
package com.dateofrock.android.test;
public class CloudWatchEndPoint {
public static final String US_EAST = "monitoring.us-east-1.amazonaws.com";
public static final String US_WEST = "monitoring.us-west-1.amazonaws.com";
public static final String EU_WEST = "monitoring.eu-west-1.amazonaws.com";
public static final String AP_SOUTHEAST = "monitoring.ap-southeast-1.amazonaws.com";
public static final String AP_NORTHEAST = "monitoring.ap-northeast-1.amazonaws.com";
}
TwitterClient.java
package com.dateofrock.android.test;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
public class TwitterClient {
public APIResult getResult(String twitterUser) {
APIResult result = new APIResult();
Twitter twitter = new TwitterFactory().getInstance();
User user;
try {
user = twitter.showUser(twitterUser);
result.followersCount = user.getFollowersCount();
result.friendsCount = user.getFriendsCount();
result.statusCount = user.getStatusesCount();
} catch (TwitterException e) {
result.error = true;
} finally {
return result;
}
}
public class APIResult {
int followersCount, friendsCount, statusCount;
private boolean error = false;
public boolean isError() {
return this.error;
}
}
}