我在 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) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:511) at 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) myFisrtQueue647) 在 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) myFisrtQueue647) 在 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) myFisrtQueuesqs.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) myFisrtQueuesqs.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) myFisrtQueueAWSSimpleQueueServiceUtil.main(AWSSimpleQueueServiceUtil.java:120) myFisrtQueueAWSSimpleQueueServiceUtil.main(AWSSimpleQueueServiceUtil.java:120) myFisrtQueue