Looking to retrieve CloudWatch logs from multiple AWS accounts using Lambda and the AWS SDK

Seeking guidance on querying CloudWatch logs across accounts using lambda and AWS SDK

  1. Developing a lambda function in typescript

  2. Deploying lambda with CloudFormation, granting necessary roles for reading from two different AWS accounts

  3. Initial execution involves:

cloudWatchLogs.startQuery(startQueryParams).promise()

to obtain queryId

  1. Subsequently, executing the following with the queryId:
cloudWatchLogs.getQueryResults(getQueryResultsParams).promise()

to retrieve required log events

Utilizing specific parameters to access log events locally:

           <{
            const startQueryParams = {
                logGroupName: this.logGroupName,
                queryString: this.queryString,`your text`
                startTime: this.startTime,
                endTime: this.endTime
           };>

If my lambda has the necessary security roles to query between accounts, how can I execute code (Lambda) from account_A to fetch log events from account_B? Obtaining account_B token and utilizing it.

Answer №1

To enable Lambda in one account to utilize CloudWatch from another account, follow these steps:

  1. Adjust the Lambda function's execution role to permit it to assume an IAM role in the second account.
  2. Establish a role in the second account that permits CloudWatch access. Update the trust policy on the IAM role to allow the Lambda function to assume this role.
  3. Integrate the AWS Security Token Service (AWS STS) AssumeRole API call into the Lambda function's code.

For more information, visit: https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-assume-iam-role/

Check out an example of AssumeRole using JavaScript SDK here: https://docs.aws.amazon.com/IAM/latest/UserGuide/example_sts_AssumeRole_section.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Express, AwsServerlessExpress, lambda, and Secrets Manager to securely export a variable from a function

Summary: I am in the process of migrating an express application to Lambda using AWS Serverless Express. One challenge I am facing is accessing Secrets Manager, where I have stored credentials for MongoDB Atlas. Issue: While I have successfully retrieved ...

Instead of the type definition file, navigate to the TypeScript source file within VS Code

A unique npm library I developed is utilized in various main projects, with all the sources stored within a /src directory and written in TypeScript. The compiler options listed in the tsconfig.json file include "sourceMap": true and "outDir": "dist". Addi ...

How can you create a unique record by appending a number in Javascript?

Currently, when a file already exists, I add a timestamp prefix to the filename to ensure it is unique. However, instead of using timestamps, I would like to use an ordinal suffix or simply append a number to the filename. I am considering adding an incr ...

The ESLint setup specified in the package.json file for eslint-config-react-app is deemed to be incorrect

The property named "overrides" has the incorrect type (expected array but received {"files":["**/*.ts","**/*.tsx"],"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":2018,"sourceType":"module","ecmaFeatures":{"jsx":true},"warnOnUnsupported ...

The subscription function in observables may result in values that are undefined

I integrated a new angular 2 library into my application called "angular2-grid". This library is located within the node_modules folder. Furthermore, I created a service as shown below: import { Injectable } from '@angular/core'; import { Htt ...

Issue: The element '[object Object]' is of type 'object', which is not supported by NgFor. NgFor only works with Iterables like Arrays. - Problem encountered in an Ionic Project

I'm currently working on retrieving my user's username from Firebase Firestore Database using Ionic and AngularFire. I have implemented the valueChanges() method to obtain the observable and am trying to process it using an async pipe. However, u ...

Reusing Angular routes across different modules for backbutton functionality

Insights on my Application (Angular 12): Comprises of 3 Modules, each containing an overview page with a list and specific detail pages Each route is assigned an area tag to identify the user's navigation within the module Goal for Angular´s RouteR ...

Interface-derived properties

One of the challenges I'm facing is dealing with a time interval encapsulation interface in TypeScript: export interface TimeBased { start_time: Date; end_time: Date; duration_in_hours: number; } To implement this interface, I've created ...

What could be the reason for encountering TypeScript within the Vue.js source code?

While exploring the vue.js source code, I stumbled upon some unfamiliar syntax that turned out to be TypeScript after further investigation. What baffled me was finding this TypeScript syntax within a ".js" file, when my understanding is that TypeScript ...

Unable to install NodeJS ejs module on AWS EC2 server

Recently, I encountered an issue while trying to deploy my nodejs application on an AWS EC2 instance. The application was working perfectly on my local machine, but when I transferred it to the live server and ran "npm install", the installation process ke ...

Utilizing Material UI and TypeScript to effectively pass custom properties to styled components

Currently, I am utilizing TypeScript(v4.2.3) along with Material UI(v4.11.3), and my objective is to pass custom props to the styled component. import React from 'react'; import { IconButton, styled, } from '@material-ui/core'; con ...

Angular: Enable function to await Observable completion before returning result

I require assistance with the user function below: getUser(uuid: string): Observable<WowUserDataModel> { let user: WowUserDataModel = { login: null, userUuid: uuid, firstName: null, lastName: null, displayName: nul ...

Is there a way to reset the yAxes count of a chart.js chart in Angular when changing tabs?

I am currently using chart.js within an Angular framework to visually display data. Is there any method available to reset the y-axis data when changing tabs? Take a look at this Stackblitz demo for reference. Upon initial loading of the page, the data ...

What is the proper way to compare enum values using the greater than operator?

Here is an example enum: enum Status { inactive = -1, active = 0, pending = 1, processing = 2, completed = 3, } I am trying to compare values using the greater than operator in a condition. However, the current comparison always results in false ...

The attribute 'close' is not present in the 'Application' data type

My approach to importing expressjs looks like this: import { Request, Response, Application, Router } from 'express'; const app: Application = require('express')(); In my typings.json file: "express": "registry:npm/express#4.14.0+20 ...

A guide on setting a default constructor as a parameter in TypeScript

Through collaboration with a fellow coder on StackOverflow, I have mastered the art of specifying a constructor as an argument to a class: type GenericConstructor<T> = { new(): T; } class MyClass<T> { subclass: T; constructor( SubClas ...

Retrieve a variable in a child component by passing it down from the parent component and triggering it from the parent

I'm struggling to grasp this concept. In my current scenario, I pass two variables to a component like this: <app-selectcomp [plid]="plid" [codeId]="selectedCode" (notify)="getCompFromChild($event)"></app-select ...

Unlock the Power of Typescript: Using the Browser Console to Access Functions

Scenario Within the file ts/app.ts, the following function exists: function foo() { console.log('Hello Word'); } After successful compilation with Webpack, it generates a file named bundle.js. To load this file, use the following script tag ...

Error in Typescript: Unable to locate module with proper type declarations

Recently embarking on a new nodejs project with typescript, I utilized Typings (https://github.com/typings/typings) to install reference files for node v4.x and express v4.x. Outlined in my setup are the following versions: Node - v4.2.6 Typescript - v1 ...

`Database Schema Enforcement in Firestore: Custom Objects vs Security Rules`

Firestore, being a noSQL database, is schemaless. However, I want to ensure that the correct data type is being passed in. Custom Objects As per Firebase documentation, https://firebase.google.com/docs/firestore/manage-data/add-data class City { const ...