API call after stack deploy updates

0

Hi team,

I have a CDK stack stackA, that creates a CloudFront distribution, already deployed in the stage and prod environments.

I want to do an API call to secretsmanager.rotateSecret each time stackA is redeployed (updating the CF distribution).

the purpose of this API call (secretsmanager.rotateSecret) is to update a header value in CF distribution with a value of a secret stored in secretmanager.

I saw that I can use AwsCustomResource to do API calls, but the onCreate, onUpdate and onDelete properties represent the lifecycle events of the custom resource itself and are invoked when the custom resource itself is created, updated or deleted respectively.

The specific scenario that I would like to achieve is

  • cdk deploy stackA (for cloudFront distribution updates)
  • once the cloudFront stack finish updating ==> then call secretsmanager.rotateSecret operation (to update a header in the CF by a value of a key stored in secret manager)

is there a way to achieve this scenario?

appreciate your help.

1 個回答
0
已接受的答案

used AwsCustomResource at the end of my CF stack

example code for secretManager Service

    const apiKeysRotationTrigger = new AwsCustomResource(
      this,
      "ident",
      {
        policy: AwsCustomResourcePolicy.fromSdkCalls({
          resources: AwsCustomResourcePolicy.ANY_RESOURCE,
        }),
        onCreate: {
          service: "SecretsManager",
          action: "rotateSecret",
          parameters: {
            SecretId: "SecretId",
          },
          physicalResourceId: PhysicalResourceId.of("PhysicalResourceId"),
        },
        onUpdate: {
          service: "SecretsManager",
          action: "rotateSecret",
          parameters: {
            SecretId: "SecretId",
          },
          physicalResourceId: PhysicalResourceId.of("PhysicalResourceId"),
        },
      }
    );
  }
Jess
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南