1. Storing API Keys for AI Model Deployment Workflows

    Python

    Storing API keys securely is an important aspect of any cloud infrastructure, especially when it comes to workflows like AI model deployment where sensitive access keys are used to authenticate against various services.

    For our purpose, let's consider we're using AWS as our cloud provider. AWS has a service called AWS Secrets Manager, which enables you to easily rotate, manage, and retrieve secrets like API keys and credentials. Below is a Pulumi program that creates a secret in AWS Secrets Manager to store an API key.

    In this program, we will:

    1. Import the necessary Pulumi AWS SDK.
    2. Use the aws.secretsmanager.Secret resource to create a new secret.
    3. Use the aws.secretsmanager.SecretVersion to add the API key as a secret string in the secret we just created.

    Please ensure you have the AWS CLI configured with the necessary credentials before running this program.

    Here's how you can use Pulumi to create the secret:

    import pulumi import pulumi_aws as aws # Create a new secret in AWS Secrets Manager to store the API key api_secret = aws.secretsmanager.Secret("apiSecret", description="API key for AI model deployment workflow") # Add the actual API key as a new version of the secret # NOTE: Replace "your-api-key-value" with the actual API key you want to store api_secret_version = aws.secretsmanager.SecretVersion("apiSecretVersion", secret_id=api_secret.id, secret_string="your-api-key-value") # Export the secret ID and version ID to easily reference the secret later on pulumi.export("secret_id", api_secret.id) pulumi.export("secret_version_id", api_secret_version.id)

    Explanation of resources used:

    • aws.secretsmanager.Secret: This creates a new secret. The secret is simply a record in AWS Secrets Manager that will hold the API key. The description property is used to describe the purpose of the secret.

    • aws.secretsmanager.SecretVersion: This adds a version to the secret, containing the API key itself. The API key is passed as a string to the secret_string argument. Make sure to replace "your-api-key-value" with your actual API key.

    After running this Pulumi program, you will get output variables secret_id and secret_version_id which can be used in other parts of your infrastructure or applications to retrieve the stored API key securely.

    You should always avoid hardcoding secrets in your codebase. Instead, you should securely fetch them at runtime using AWS SDKs or other means depending on the environment where your application is running.