I've been trying to do a very simple test using AWS SQS. My goal is to send a message via a react application. My setup is this:
- AWS FIFO Queue configured
- IAM user created and allowed to use SQS
- Installed CLI v2 and made a test to send a message using shared credentials file: All good!
Based on AWS documentation I've wrote the following lines of code:
import awsConfig from 'aws-config';
import React from 'react'
const {SQSClient, SendMessageCommand} = require('@aws-sdk/client-sqs');
var AWS = require('aws-sdk');
const CONFIG = require('aws-config');
const REGION = "my region"
const params ={
MessageBody:"test message",
MessageDeduplicationId: "dedup",
MessageGroupId: "group1",
QueueUrl: "https://my queue-url.fifo"
}
const sqsconfig = new AWS.Config({
accessKeyId: 'my access key',
secretAccessKey: 'my secret key',
region: 'my region',
endpoint: 'my endpoint'
});
const sqs = new SQSClient();
const send = async () => {
try {
console.log("trying to send message")
sqs.config = sqsconfig
console.log(sqs.config)
const r = await sqs.send(new SendMessageCommand(params));
console.log("Message Sent Successfully!")
} catch (error) {
console.log(error)
}
}
const AWSSQS = props => {
return (
<div>
<label>queue</label>
<input type='text' style={{width:500}} />
<p>
<label>message</label>
<input type='text' style={{width:500}} />
</p>
<button onClick={send}>Send Message</button>
</div>
)
}
export default AWSSQS
Upon execution, I'm getting a Type Error: Context.endpoint is not a function. If I try to omit the endpoint property on sqsconfig, I get the same error. If I omit sqs.config part, I get a Missing Credentials error.
Am I missing something?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…