Closed eau-de-la-seine closed 1 year ago
Hi @eau-de-la-seine , thanks for reporting. Please note that this is a client-side error, which LocalStack has no control over. We usually recommend setting either a local test profile, or the following environment variables to get started:
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
Please note that these configurations are already built into all utilities that LocalStack is providing (e.g., awslocal
, cdklocal
, etc), but when you're using the raw AWS SDK clients, you'll need to configure things manually. Please keep us posted on how it goes.. Thanks!
Hi @whummer , yes I'm using an AWS SDK lib in my application (and I guess that a lot of people use Localstack for testing their applications instead of using command line tools for testing Localstack), but what I'm trying to say is that Localstack is supposed to emulate the AWS environment on my computer, but AWS environment doesn't throw misleading errors like CredentialsProviderError: Could not load credentials from any providers
because it wouldn't find some [default]
profile in .aws/credentials
That's why the localstack start
command could (that's a proposal) add:
[default]
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
if [default]
does not already exist.
Thanks
Hello 👋! It looks like this issue hasn’t been active in longer than five months. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.
`import { Express, Request, Response } from "express"; import express from "express"; import cors from "cors"; import multer from "multer"; import { v4 } from "uuid"; import { StorageType, Storage } from "@tweedegolf/storage-abstraction"; import { DocumentService_Name } from "./actors/doc/doc-types.js"; import path from "path"; import fs from "fs"; import { config } from "./config.js"; import { initModulo } from "lib-js-s-modulo/index.mjs";
const app: Express = express();
app.use(cors()); app.use(express.json());
const s3Config = {
type: StorageType.S3, accessKeyId: "AKIAVRCYVD3UZTTC6QK7", secretAccessKey: "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", region: "ap-south-1", bucketName: "kpil-doc-prod", useDualStack: true, sslEnabled: true, };
const temporaryPath = config.actors.find( (a: any) => a.name === DocumentService_Name )?.config["temporaryPath"]; // const temporaryPath = // "C:\Users\hp-iripl2\Desktop\kpl\new-kpt-server-admin\kpt-admin-server\server";
// Create an instance of the Storage class const storage = new Storage(s3Config);
const upload = multer({ dest: temporaryPath });
app.post("/upload-file", upload.single("file"), async (req, res) => { try { if (!req.file) { console.error("No file uploaded."); return res.status(400).json({ error: "No file uploaded" }); }
const uploadedFile = req.file;
const fileId: any = v4(); // Generate a unique file identifier
// Read the file into a buffer
// const fileBuffer: any = fs.readFileSync(uploadedFile.path);
const filePath = uploadedFile.path;
// Upload the file to S3 using the storage abstraction library
await storage.addFileFromPath(fileId, filePath);
// Remove the temporary file
// fs.unlinkSync(filePath);
res.json({ fileId: uploadedFile.filename });
} catch (error) { console.error("Error uploading file:", error); res.status(500).json({ error: "File upload failed" }); } });
// ...
app.use("/view-file", express.static(temporaryPath));
app.get("/", (req: Request, res: Response) => {
res.send(Welcome to ${config.appName}
);
});
initModulo({ config, app });
app.listen(config.port, () => {
console.log(
⚡️[server]: Server is running at http://localhost:${config.port}
);
});
`
this code is also showing same error
Is there an existing issue for this?
Current Behavior
When I use the AWS SDK v3 client:
=> I have the following exception:
CredentialsProviderError: Could not load credentials from any providers
Expected Behavior
I should be able to use Localstack without this exception.
This exception happens because either AWS client or Localstack implementation is looking for a
[default]
profile in.aws/credentials
, but[default]
profile does not existThis exception is very tricky because developers do not understand the source cause of this problem, some do unnecessary hack fix on their client to bypass this problem
My proposal
If the problem comes from the Localstack implementation: Don't check for a
[default]
AWS profile, it shouldn't be necessary anywayIf the problem comes from the AWS client: Add a
[default]
block in.aws/credentials
if it does not already exist when Localstack starts:How are you starting LocalStack?
With the
localstack
scriptSteps To Reproduce
This exception happens because either AWS client or Localstack implementation is looking for a
[default]
profile in.aws/credentials
, but[default]
profile does not existEnvironment
Anything else?
No response