Skip to content

comet_ml.secrets.aws ¶

get_api_key_from_secret_manager ¶

get_api_key_from_secret_manager(
    secret_name: str,
    secret_version: str,
    aws_region_name: Optional[str] = None,
    aws_profile_name: Optional[str] = None,
) -> str

Returns a Comet API Key Secret that can be used instead of a clear-text API Key when creating an Experiment or API object. The Comet API Key Secret is a string that represents the location of the secret in the AWS Secret Manager without containing the API Key. This means that this function don't need permission or access to AWS Secret Manager.

Parameters:

  • secret_name (str) –

    AWS secret name.

  • secret_version (str) –

    AWS secret version. You can get this value from the comet_ml.secrets.aws.store_api_key_in_secret_manager output. You can also pass "latest", in that case the function will return a Comet API Key Secret pointing to the latest version of the AWS Secret.

  • aws_region_name (Optional[str], default: None ) –

    AWS region name. If not specified the default region name from the local AWS configuration will be used.

  • aws_profile_name (Optional[str], default: None ) –

    AWS profile name. If not specified the default profile name from the local AWS configuration will be used.

Returns:

  • str –

    (str) Comet API Key Secret.

Example
1
2
3
4
api_key = get_api_key_from_secret_manager(
    AWS_SECRET_NAME, aws_region_name="us-east-1" ,aws_profile_name="dev"
)
experiment = comet_ml.Experiment(api_key=api_key)

store_api_key_in_secret_manager ¶

store_api_key_in_secret_manager(
    api_key: str,
    secret_name: str,
    aws_region_name: Optional[str] = None,
    aws_profile_name: Optional[str] = None,
) -> Tuple[str, str]

Stores an API key to AWS Secret Manager as a secret. After that returns an API Key Secret and AWS Secret version as a string.

Parameters:

  • api_key (str) –

    Comet API key to save.

  • secret_name (str) –

    AWS secret name.

  • aws_region_name (Optional[str], default: None ) –

    AWS region name. If not specified the default region name from the local AWS configuration will be used.

  • aws_profile_name (Optional[str], default: None ) –

    AWS profile name. If not specified the default profile name from the local AWS configuration will be used.

Example
1
2
3
4
api_key_secret, secret_version = store_api_key_in_secret_manager(
    COMET_API_KEY, AWS_SECRET_NAME
)
experiment = comet_ml.Experiment(api_key=api_key_secret)
Jul. 25, 2024