- Newest
- Most votes
- Most comments
Got the solution from AWS support team.
import { CognitoIdentityProviderClient, CreateUserImportJobCommand, StartUserImportJobCommand } from "@aws-sdk/client-cognito-identity-provider"; import axios from 'axios'; import fs from 'fs';
// Read the CSV file into a Buffer. const filePath = 'template.csv'; const fileBuffer = fs.readFileSync(filePath); const client = new CognitoIdentityProviderClient({ region: "us-east-1" });
console.log('Creating Import job\n'); const params = { "CloudWatchLogsRoleArn": "<IAMRoleARN>", "JobName": "TestNode", "UserPoolId": "<UserPoolId>" }; const command = new CreateUserImportJobCommand(params); const response = await client.send(command); const url = response.UserImportJob.PreSignedUrl; const job_id = response.UserImportJob.JobId; console.log('Presigned Url: ', url);
// Make an HTTP POST request to the presigned URL.
await axios.put(url, fileBuffer, {
headers: {
'Content-Type': 'text/csv',
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
'Access-Control-Allow-Credentials': true, // Required for cookies, authorization headers with HTTPS
'x-amz-server-side-encryption': 'aws:kms'
},
})
.then(response => {
console.log(File uploaded successfully with status ${response.status}
);
})
.catch(error => {
console.error('Error uploading file:', error); });
console.log('Starting Import job'); const params2 = { "JobId": job_id, "UserPoolId": "<UserPoolId>" }
const command2 = new StartUserImportJobCommand(params2); const response2 = await client.send(command2); console.log(response2)
The first consideration is whether each of the guidance steps located in the documentation link below are applicable and have been followed. Cognito user pool import
Relevant content
- asked 6 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago