1. Secure Credential Rotation for AI Services with AWS SSM Association

    Python

    In order to manage secure credential rotation for AI services using AWS Systems Manager (SSM) State Manager, we'll leverage the AWS SSM Association resource that Pulumi provides. AWS SSM can help you to automate the process of updating and rotating secrets for different AWS services, including AI services.

    The AWS SSM Association resource is useful to apply an SSM document to a set of targets, typically EC2 instances or other managed instances in your environment. However, when dealing with sensitive credentials, you enter the realm of SSM Parameter Store and AWS Secrets Manager where you can store, manage, and rotate secrets.

    You would typically store your AI service credentials as secure strings in SSM Parameter Store or AWS Secrets Manager, then you would set up rotation policies using AWS Secrets Manager primarily, which would involve creating a custom Lambda function to handle the rotation logic specific to the AI service's API credential requirements.

    Here's a Pulumi program in Python that sets up secure secret rotation for an AI service using AWS Secrets Manager. This involves creating a secret, defining rotation rules, and configuring a custom Lambda function to rotate the secret.

    import pulumi import pulumi_aws as aws # Create a new secret to store the AI service credentials ai_service_secret = aws.secretsmanager.Secret("aiServiceSecret", description="AI Service credentials", # More properties can be added here such as KMS Key ID, tags, etc. ) # The documentation for the aws.secretsmanager.Secret resource can be found here: # https://www.pulumi.com/registry/packages/aws/api-docs/secretsmanager/secret/ # Now, let's create a Lambda function that will handle the rotation logic # This is just a placeholder function; you will need to implement your own logic rotation_lambda = aws.lambda_.Function("rotationLambda", code=pulumi.AssetArchive({ ".": pulumi.FileArchive("./path_to_your_lambda_code"), }), handler="index.handler", role=lambda_role.arn, runtime="python3.8", ) # The lambda_role is an IAM role that you must define with appropriate permissions lambda_role = aws.iam.Role("lambdaRole", assume_role_policy="""{ "Version": "2012-10-17", "Statement": [{ "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, }] }""") # Now that you have your Lambda function ready, you can configure a secret rotation policy ai_service_secret_rotation = aws.secretsmanager.SecretRotation("aiServiceSecretRotation", secret_id=ai_service_secret.id, rotation_lambda_arn=rotation_lambda.arn, rotation_rules={ "automatically_after_days": 30, # Rotate automatically every 30 days } ) # The documentation for the aws.secretsmanager.SecretRotation resource can be found here: # https://www.pulumi.com/registry/packages/aws/api-docs/secretsmanager/secretrotation/ # Finally, output the ARN of the secret, so you know where to access it pulumi.export('ai_service_secret_arn', ai_service_secret.arn)

    In this program, we created an AWS Secrets Manager secret for storing AI service credentials, then created a Lambda function that contains rotation logic. This Lambda function is then tied to the secret via a rotation policy that will execute the rotation based on the criteria specified (every 30 days in this example).

    Please note that you need to replace "./path_to_your_lambda_code" with the actual path to your Lambda function code. The Lambda function must have the logic to interact with the corresponding AI service for rotating and updating the credentials in a way that adheres to the AI service's requirements for credentials.

    You would need to ensure that you have the required IAM role (lambda_role in the example) and policies in place for the Lambda function to perform the secrets rotation. This includes permissions to invoke the Lambda, update the secret, and any other actions that the specific AI service might require for credential rotation.

    Remember, rotating credentials securely is a complex process that involves careful planning and implementation to guarantee that new credentials are set and propagated without interrupting the service. This example provides a starting point, but the specific implementation details will vary depending on the AI service in question and your organization's specific requirements and policies.