mirror of
https://github.com/morten-olsen/with-ssm.git
synced 2026-02-08 00:46:23 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14c4d5c386 |
@@ -1,4 +1,4 @@
|
|||||||
import { GetParametersCommand, SSMClient } from '@aws-sdk/client-ssm';
|
import { GetParametersCommand, SSMClient, type Parameter } from '@aws-sdk/client-ssm';
|
||||||
|
|
||||||
import { debug } from './debug.js';
|
import { debug } from './debug.js';
|
||||||
|
|
||||||
@@ -30,18 +30,42 @@ const replaceParams = async (
|
|||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chunk names into groups of 10 (AWS SSM GetParametersCommand limit)
|
||||||
|
const chunks: string[][] = [];
|
||||||
|
debug(`Chunking ${names.length} names into groups of 10`);
|
||||||
|
for (let i = 0; i < names.length; i += 10) {
|
||||||
|
chunks.push(names.slice(i, i + 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(`Processing ${chunks.length} chunks`);
|
||||||
|
|
||||||
|
// Fetch parameters in chunks and combine results
|
||||||
|
const allParams: Parameter[] = [];
|
||||||
|
const allInvalidParams: string[] = [];
|
||||||
|
|
||||||
|
for (const chunk of chunks) {
|
||||||
const command = new GetParametersCommand({
|
const command = new GetParametersCommand({
|
||||||
Names: names,
|
Names: chunk,
|
||||||
WithDecryption: true,
|
WithDecryption: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await ssm.send(command);
|
const response = await ssm.send(command);
|
||||||
if (response.InvalidParameters?.length || 0 > 0) {
|
|
||||||
console.error('Invalid SSM parameters', response.InvalidParameters);
|
if (response.Parameters) {
|
||||||
|
allParams.push(...response.Parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.InvalidParameters) {
|
||||||
|
allInvalidParams.push(...response.InvalidParameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allInvalidParams.length > 0) {
|
||||||
|
console.error('Invalid SSM parameters', allInvalidParams);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = response.Parameters ?? [];
|
const params = allParams;
|
||||||
|
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(env).map(([key, value]) => {
|
Object.entries(env).map(([key, value]) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user