Created
August 20, 2021 11:43
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { captureAWSv3Client } from "aws-xray-sdk"; | |
import { IAM } from "@aws-sdk/client-iam"; | |
import { SecretsManager } from "@aws-sdk/client-secrets-manager"; | |
export interface RotateAccessKeyEvent { | |
iamUserName: string; | |
secretId: string; | |
} | |
const iamClient = captureAWSv3Client(new IAM({})); | |
const secretsManagerClient = captureAWSv3Client(new SecretsManager({})); | |
export const handler = async (event: RotateAccessKeyEvent) => { | |
console.log(`rotate access key for user ${event.iamUserName}`); | |
const accessKey = await iamClient.createAccessKey({ | |
UserName: event.iamUserName, | |
}); | |
await secretsManagerClient.putSecretValue({ | |
SecretId: event.secretId, | |
SecretString: JSON.stringify({ | |
accessKeyId: accessKey.AccessKey?.AccessKeyId || "", | |
secretAccessKey: accessKey.AccessKey?.SecretAccessKey || "", | |
}), | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment