def create(
        cls,
        action_name=None,
        source_uri=None,
        source_type=None,
        action_type=None,
        description=None,
        status=None,
        properties=None,
        tags=None,
        sagemaker_session=None,
    ):
        """Create an action and return an ``Action`` object representing it.

        Args:
            action_name (str): Name of the action
            source_uri (str): Source URI of the action
            source_type (str): Source type of the action
            action_type (str): The type of the action
            description (str): Description of the action
            status (str): Status of the action.
            properties (dict): key/value properties
            tags (dict): AWS tags for the action
            sagemaker_session (sagemaker.session.Session): Session object which
                manages interactions with Amazon SageMaker APIs and any other
                AWS services needed. If not specified, one is created using the
                default AWS configuration chain.

        Returns:
            Action: A SageMaker ``Action`` object.
        """
        return super(Action, cls)._construct(
            cls._boto_create_method,
            action_name=action_name,
            source=_api_types.ContextSource(source_uri=source_uri,
                                            source_type=source_type),
            action_type=action_type,
            description=description,
            status=status,
            properties=properties,
            tags=tags,
            sagemaker_session=sagemaker_session,
        )
    def create(
        cls,
        context_name: str = None,
        source_uri: str = None,
        source_type: str = None,
        context_type: str = None,
        description: str = None,
        properties: dict = None,
        tags: dict = None,
        sagemaker_session=None,
    ) -> "Context":
        """Create a context and return a ``Context`` object representing it.

        Args:
            context_name (str): The name of the context.
            source_uri (str): The source URI of the context.
            source_type (str): The type of the source.
            context_type (str): The type of the context.
            description (str): Description of the context.
            properties (dict): Metadata associated with the context.
            tags (dict): Tags to add to the context.
            sagemaker_session (sagemaker.session.Session): Session object which
                manages interactions with Amazon SageMaker APIs and any other
                AWS services needed. If not specified, one is created using the
                default AWS configuration chain.

        Returns:
            Context: A SageMaker ``Context`` object.
        """
        return super(Context, cls)._construct(
            cls._boto_create_method,
            context_name=context_name,
            source=_api_types.ContextSource(source_uri=source_uri,
                                            source_type=source_type),
            context_type=context_type,
            description=description,
            properties=properties,
            tags=tags,
            sagemaker_session=sagemaker_session,
        )
Exemple #3
0
    def create(
        cls,
        artifact_name=None,
        source_uri=None,
        source_types=None,
        artifact_type=None,
        properties=None,
        tags=None,
        sagemaker_session=None,
    ):
        """Create an artifact and return an ``Artifact`` object representing it.

        Args:
            artifact_name (str, optional): Name of the artifact
            source_uri (str, optional): Source URI of the artifact
            source_types (list, optional): Source types
            artifact_type (str, optional): Type of the artifact
            properties (dict, optional): key/value properties
            tags (dict, optional): AWS tags for the artifact
            sagemaker_session (sagemaker.session.Session): Session object which
                manages interactions with Amazon SageMaker APIs and any other
                AWS services needed. If not specified, one is created using the
                default AWS configuration chain.

        Returns:
            Artifact: A SageMaker ``Artifact`` object.
        """
        return super(Artifact, cls)._construct(
            cls._boto_create_method,
            artifact_name=artifact_name,
            source=_api_types.ContextSource(source_uri=source_uri,
                                            source_types=source_types),
            artifact_type=artifact_type,
            properties=properties,
            tags=tags,
            sagemaker_session=sagemaker_session,
        )
Exemple #4
0
def test_list(sagemaker_session):
    creation_time = datetime.datetime.now(
        datetime.timezone.utc) + datetime.timedelta(hours=3)
    last_modified_time = datetime.datetime.now(
        datetime.timezone.utc) + datetime.timedelta(hours=4)

    sagemaker_session.sagemaker_client.list_contexts.side_effect = [
        {
            "ContextSummaries": [{
                "ContextName":
                "A" + str(i),
                "ContextArn":
                "B" + str(i),
                "Source": {
                    "SourceUri": "test-source-uri" + str(i),
                    "SourceType": "test-source-type" + str(i),
                },
                "ContextType":
                "test-context-type",
                "CreationTime":
                creation_time + datetime.timedelta(hours=i),
                "LastModifiedTime":
                last_modified_time + datetime.timedelta(hours=i),
                "LastModifiedBy": {},
            } for i in range(10)],
            "NextToken":
            "100",
        },
        {
            "ContextSummaries": [{
                "ContextName":
                "A" + str(i),
                "ContextArn":
                "B" + str(i),
                "Source": {
                    "SourceUri": "test-source-uri" + str(i),
                    "SourceType": "test-source-type" + str(i),
                },
                "ContextType":
                "test-context-type",
                "CreationTime":
                creation_time + datetime.timedelta(hours=i),
                "LastModifiedTime":
                last_modified_time + datetime.timedelta(hours=i),
                "LastModifiedBy": {},
            } for i in range(10, 20)]
        },
    ]

    expected = [
        _api_types.ContextSummary(
            context_name="A" + str(i),
            context_arn="B" + str(i),
            source=_api_types.ContextSource(
                source_uri="test-source-uri" + str(i),
                source_type="test-source-type" + str(i)),
            context_type="test-context-type",
            creation_time=creation_time + datetime.timedelta(hours=i),
            last_modified_time=last_modified_time +
            datetime.timedelta(hours=i),
            last_modified_by={},
        ) for i in range(20)
    ]
    result = list(
        context.Context.list(
            source_uri="foo",
            sagemaker_session=sagemaker_session,
            sort_by="CreationTime",
            sort_order="Ascending",
        ))

    assert expected == result
    expected_calls = [
        unittest.mock.call(SortBy="CreationTime",
                           SortOrder="Ascending",
                           SourceUri="foo"),
        unittest.mock.call(NextToken="100",
                           SortBy="CreationTime",
                           SortOrder="Ascending",
                           SourceUri="foo"),
    ]
    assert expected_calls == sagemaker_session.sagemaker_client.list_contexts.mock_calls