Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - AWS SQS SendMessage test using React Native

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...