Skip to content

Commit

Permalink
fix: use Math.random to generate a uid for GuSSMParameter
Browse files Browse the repository at this point in the history
Using the clock (via `Date.now()` or `performance.now()`) isn't reliably producing unique numbers, switch to `Math.random`.
  • Loading branch information
akash1810 committed Apr 1, 2021
1 parent 98e6a5b commit 3285bf9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/constructs/core/ssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ export class GuSSMParameter extends Construct implements IGrantable {
readonly grantPrincipal: IPrincipal;

static id = (prefix: string, parameter: string): string => {
const now = Date.now().toString();
// We need to create UIDs for the resources in this construct, as otherwise CFN will not trigger the lambda on updates for resources that appear to be the same
const uid = now.substr(now.length - 4);
const randomNumberBetweenOneAndTenThousand = Math.floor(Math.random() * 10000) + 1;
return parameter.toUpperCase().includes("TOKEN")
? `${prefix}-token-${uid}`
: `${prefix}-${stripped(parameter)}-${uid}`;
? `${prefix}-token-${randomNumberBetweenOneAndTenThousand}`
: `${prefix}-${stripped(parameter)}-${randomNumberBetweenOneAndTenThousand}`;
};

constructor(scope: GuStack, props: GuSSMParameterProps) {
Expand Down

0 comments on commit 3285bf9

Please sign in to comment.