Closed TarunYadavG closed 4 months ago
@ktj-ph can you help me with this?
Hi @TarunYadavG , thanks for your interest! What is the need to convert this into Java? From the error code it seems like the client has not provided valid credentials or authorization. "Perhaps AWS is restricting access to retrieve the data via API" > I can confirm that this works with the provided python code, so I think this has more to do with how you convert this to Java & getting the right signin token.
@ktj-ph Okay, let me recheck and see if I made any mistakes on my end during the conversion. I thought AWS was blocking.
Using TypeScript, I'm getting the same 401 error when requesting /billing/rest/api-proxy/carbonfootprint.
Due to the fact that we want our future projects to be in TypeScript, Python is not our primary language.
I have found the solution: In the example, all requests are sent in a (requests.)Session. In my TS Lambda, I'm using axios for the requests. But in this case, every request happens in its own session. For TS with axios, I added tough-cookie and http-cookie-agent packages. With those I can create a session in my lambda, where every request via client stores the information like cookies in the session and the Lambda is authorized to request the carbon emissions.
const jar = new CookieJar();
const client = axios.create({
httpAgent: new HttpCookieAgent({cookies: {jar}}),
httpsAgent: new HttpsCookieAgent({cookies: {jar}}),
})
const loginResponse = await client.get(signinTokenUrl); // use the client instead of axios
@TarunYadavG: I guess this would be the fix for you too.
I'm using the same process as mentioned in the project. I'm trying to employ a specific method from https://github.com/aws-samples/experimental-programmatic-access-ccft/blob/main/MultiAccountApplication/lambda-functions/3_backfill_data/ccft_access.py to retrieve carbon footprint data. However, after converting it to Java, I encountered the following exception.
I am making API calls from the child account, not the master one, and I'm unsure about what might be missing here. I have added the IAM policy to my account and verified the validity of the credentials by listing EC2 instances, from which I successfully obtained data, indicating that credentials are not the issue. Perhaps AWS is restricting access to retrieve the data via API, but I'm uncertain.
Furthermore, I can confirm that I am able to view the carbon footprint data for my account, indicating that the data does exist.
IAM policy
Snippet
Exception:
Could anyone provide assistance?