def _replace_local_codeuri()

in src/cfnlint/transform.py [0:0]


    def _replace_local_codeuri(self):
        """
        Replaces the CodeUri in AWS::Serverless::Function and DefinitionUri in
        AWS::Serverless::Api to a fake S3 Uri. This is to support running the
        SAM Translator with valid values for these fields. If this is not done,
        the template is invalid in the eyes of SAM Translator (the translator
        does not support local paths)
        """

        all_resources = self._template.get('Resources', {})

        template_globals = self._template.get('Globals', {})
        auto_publish_alias = template_globals.get('Function', {}).get('AutoPublishAlias')
        if isinstance(auto_publish_alias, dict):
            if len(auto_publish_alias) == 1:
                for k, v in auto_publish_alias.items():
                    if k == 'Ref':
                        if v in self._template.get('Parameters'):
                            self._parameters[v] = 'Alias'


        for _, resource in all_resources.items():

            resource_type = resource.get('Type')
            resource_dict = resource.get('Properties')

            if resource_type == 'AWS::Serverless::Function':

                Transform._update_to_s3_uri('CodeUri', resource_dict)
                auto_publish_alias = resource_dict.get('AutoPublishAlias')
                if isinstance(auto_publish_alias, dict):
                    if len(auto_publish_alias) == 1:
                        for k, v in auto_publish_alias.items():
                            if k == 'Ref':
                                if v in self._template.get('Parameters'):
                                    self._parameters[v] = 'Alias'
            if resource_type in ['AWS::Serverless::LayerVersion']:
                if resource_dict.get('ContentUri'):
                    Transform._update_to_s3_uri('ContentUri', resource_dict)
            if resource_type == 'AWS::Serverless::Application':
                if resource_dict.get('Location'):
                    resource_dict['Location'] = ''
                    Transform._update_to_s3_uri('Location', resource_dict)
            if resource_type == 'AWS::Serverless::Api':
                if ('DefinitionBody' not in resource_dict and
                        'Auth' not in resource_dict and 'Cors' not in resource_dict):
                    Transform._update_to_s3_uri('DefinitionUri', resource_dict)
                else:
                    resource_dict['DefinitionBody'] = ''
            if resource_type == 'AWS::Serverless::StateMachine' and resource_dict.get('DefinitionUri'):
                Transform._update_to_s3_uri('DefinitionUri', resource_dict)