I'm developing an app using react native and aws amplify. I implemented a push notification using AWS SNS, Pinpoint, and Google Firebase and successfully tested it on the Amazon pinpoint test messaging page(From the Firebase test page is also successful). However, when I tried to send the push notification with my code, I encountered a problem. Below is the code to send the push notification.
const AWS = require('aws-sdk');
const region = 'myRegion';
const applicationId = 'pinpoint_project_appId';
const sendPushNotification = async () => {
const messageRequest = CreateMessageRequest();
AWS.config.update({region: region});
const credentials = {
accessKeyId: AWS_ACCESS_KEY,
accessSecretKey: AWS_SECRET_KEY,
// AWS_ACCESS_KEY_ID: AWS_ACCESS_KEY,
// AWS_SECRET_ACCESS_KEY: AWS_SECRET_KEY,
// aws_access_key_id: AWS_ACCESS_KEY,
// aws_secret_access_key: AWS_SECRET_KEY,
};
AWS.config.credentials = credentials;
const pin = new AWS.Pinpoint();
console.log(pin);
const params = {
ApplicationId: applicationId,
MessageRequest: messageRequest,
};
pin.sendMessages(params, function (err, data) {
if (err) console.error(err);
else console.dir(data);
});
};
I got "[CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1]" error from "pin.sendMessages" code.
I searched stackoverflow and found that I need to add credentials to AWS.config. So I added AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, but I still get the same error.
In console.log(pin); credentials is output as follows : "credentials": {"accessKeyId": "MyAccessKeyId", "accessSecretKey": "MyAccessSecretKey"}
I created the ACCESS KEY in the Amplify IAM console and selected the "Other" as "Use case" when creating it.
If you know anything, please help me. And If there are any settings(project, amplify...) or other code needed to advise me, please let me know.
Thanks.