我正在ec2上运行我的简单类,以在SQS上创建或发送消息。但这给了我服务:AmazonSQS;状态码:403;错误代码:SignatureDoesNotMatch;
我正在附上我的代码和以下错误:-
private AWSSimpleQueueServiceUtil() {
try {
this.simpleQueue = "demo-Photo-Queue";
//this.sqs = (AmazonSQS) AmazonSQSClientBuilder.standard().build();
//this.sqs.setEndpoint("https://a4b.us-east-1.amazonaws.com");
this.sqs = (AmazonSQS) AmazonSQSClientBuilder.standard()
.withRegion(Regions.US_EAST_1)
.build();
} catch (Exception e) {
System.out.println("exception while creating awss3client : " + e);
}
}
public static AWSSimpleQueueServiceUtil getInstance() {
return awssqsUtil;
}
public AmazonSQS getAWSSQSClient() {
return awssqsUtil.sqs;
}
public String getQueueName() {
return awssqsUtil.simpleQueue;
}
/**
* Creates a queue in your region and returns the url of the queue
*
* @param queueName
* @return
*/
public String createQueue(String queueName) {
CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
String queueUrl = this.sqs.createQueue(createQueueRequest).getQueueUrl();
return queueUrl;
}
/**
* returns the queueurl for for sqs queue if you pass in a name
*
* @param queueName
* @return
*/
public String getQueueUrl(String queueName) {
GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName);
return this.sqs.getQueueUrl(getQueueUrlRequest).getQueueUrl();
}
/**
* send a single message to your sqs queue
*
* @param queueUrl
* @param message
*/
public void sendMessageToQueue(String queueUrl, String message) {
SendMessageResult messageResult = this.sqs.sendMessage(new SendMessageRequest(queueUrl, message));
System.out.println(messageResult.toString());
System.out.println("send successfully");
}
public static void main(String[] args) throws UnsupportedEncodingException {
//String thePath = "https://sqs.us-east-1.amazonaws.com/685308457175/demo-Photo-Queue";
String queueName = "myFisrtQueue";
queueName = URLEncoder.encode(queueName, "UTF-8");
System.out.println(queueName);
AWSSimpleQueueServiceUtil.getInstance().createQueue("queueName");
}
以下是我收到的错误:-
(服务:AmazonSQS;状态代码:403;错误代码:SignatureDoesNotMatch;请求ID:20311998-3b24-5878-a1d6-4d5cdc182fa2) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1592) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeOneRequest(AmazonHttpClient.java:1257) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeHelper(AmazonHttpClient.java:1029) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.doExecute(AmazonHttpClient.java:741) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeWithTimer(AmazonHttpClient.java:715) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.execute(AmazonHttpClient.java:697) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.access $ 500(AmazonHttpClient.java:665) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:647) 在com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:511) 在com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:1740) 在com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:1716) 在com.amazonaws.services.sqs.AmazonSQSClient.executeSendMessage(AmazonSQSClient.java:1503) 在com.amazonaws.services.sqs.AmazonSQSClient.sendMessage(AmazonSQSClient.java:1480) 在com.SQSDemojava.demo.AWSSimpleQueueServiceUtil.sendMessageToQueue(AWSSimpleQueueServiceUtil.java:87) 在com.SQSDemojava.demo.AWSSimpleQueueServiceUtil.main(AWSSimpleQueueServiceUtil.java:120) myFisrtQueue