UNPKG

@cloud-copilot/iam-collect

Version:

Collect IAM information from AWS Accounts

52 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamoDbStreamsSync = void 0; const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); const client_dynamodb_streams_1 = require("@aws-sdk/client-dynamodb-streams"); const client_tools_js_1 = require("../../utils/client-tools.js"); const json_js_1 = require("../../utils/json.js"); const sync_js_1 = require("../sync.js"); const typedSync_js_1 = require("../typedSync.js"); exports.DynamoDbStreamsSync = { awsService: 'dynamodb', name: 'dynamoDbStreams', execute: async (accountId, region, credentials, storage, endpoint, syncOptions) => { const streamsClient = syncOptions.clientPool.client(client_dynamodb_streams_1.DynamoDBStreamsClient, credentials, region, endpoint); const dynamoClient = syncOptions.clientPool.client(client_dynamodb_1.DynamoDBClient, credentials, region, endpoint); const allStreams = await (0, typedSync_js_1.paginateResource)(streamsClient, client_dynamodb_streams_1.ListStreamsCommand, 'Streams', { inputKey: 'ExclusiveStartStreamArn', outputKey: 'LastEvaluatedStreamArn' }); const streams = []; for (const stream of allStreams) { const streamArn = stream.StreamArn; const tableName = streamArn.split('/')[1]; const policy = await (0, client_tools_js_1.runAndCatchError)('PolicyNotFoundException', async () => { const result = await dynamoClient.send(new client_dynamodb_1.GetResourcePolicyCommand({ ResourceArn: streamArn })); return (0, json_js_1.parseIfPresent)(result.Policy); }); streams.push({ arn: streamArn, metadata: { arn: streamArn, label: stream.StreamLabel, tableName, stream: 'true' }, policy }); } await (0, sync_js_1.syncData)(streams, storage, accountId, { // Stream ARNS start with the table ARN, so we use table as the resource type // and then set the metadata to indicate that this is a stream resource service: 'dynamodb', resourceType: 'table', account: accountId, region: region, metadata: { stream: 'true' } }, syncOptions.writeOnly); } }; //# sourceMappingURL=dynamoDbStreams.js.map