|
13 | 13 | import hashlib |
14 | 14 | import json |
15 | 15 | import os |
16 | | -import platform |
17 | 16 | import shutil |
18 | 17 | import subprocess |
19 | 18 | import sys |
@@ -53,7 +52,7 @@ def __init__(self, verbose=False): |
53 | 52 | self.public = False |
54 | 53 | self.main_template = "idp-main.yaml" |
55 | 54 | self.use_container_flag = "" |
56 | | - self.stat_cmd = None |
| 55 | + |
57 | 56 | self.s3_client = None |
58 | 57 | self.cf_client = None |
59 | 58 | self._is_lib_changed = False |
@@ -228,12 +227,6 @@ def setup_environment(self): |
228 | 227 | self.prefix_and_version = f"{self.prefix}/{self.version}" |
229 | 228 | self.bucket = f"{self.bucket_basename}-{self.region}" |
230 | 229 |
|
231 | | - # Set platform-specific commands |
232 | | - if platform.machine() == "x86_64": |
233 | | - self.stat_cmd = "stat --format='%Y'" |
234 | | - else: |
235 | | - self.stat_cmd = "stat -f %m" |
236 | | - |
237 | 230 | # Set UDOP model path based on region |
238 | 231 | if self.region == "us-east-1": |
239 | 232 | self.public_sample_udop_model = "s3://aws-ml-blog-us-east-1/artifacts/genai-idp/udop-finetuning/rvl-cdip/model.tar.gz" |
@@ -883,57 +876,33 @@ def _check_requirements_has_idp_common_pkg(self, func_dir): |
883 | 876 | def _extract_function_name(self, dir_name, template_path): |
884 | 877 | """Extract CloudFormation function name from template by matching CodeUri.""" |
885 | 878 | try: |
886 | | - import yaml |
887 | | - |
888 | | - # Create a custom loader that ignores CloudFormation intrinsic functions |
889 | | - class CFLoader(yaml.SafeLoader): |
890 | | - pass |
891 | | - |
892 | | - def construct_unknown(loader, node): |
893 | | - return None |
894 | | - |
895 | | - # Add constructors for CloudFormation intrinsic functions |
896 | | - cf_functions = [ |
897 | | - "!Ref", |
898 | | - "!GetAtt", |
899 | | - "!Join", |
900 | | - "!Sub", |
901 | | - "!Select", |
902 | | - "!Split", |
903 | | - "!Base64", |
904 | | - "!GetAZs", |
905 | | - "!ImportValue", |
906 | | - "!FindInMap", |
907 | | - "!Equals", |
908 | | - "!And", |
909 | | - "!Or", |
910 | | - "!Not", |
911 | | - "!If", |
912 | | - "!Condition", |
913 | | - ] |
914 | | - |
915 | | - for func in cf_functions: |
916 | | - CFLoader.add_constructor(func, construct_unknown) |
917 | | - |
918 | | - with open(template_path, "r") as f: |
919 | | - template = yaml.load(f, Loader=CFLoader) |
920 | | - |
921 | | - resources = template.get("Resources", {}) |
922 | | - for resource_name, resource_config in resources.items(): |
923 | | - if ( |
924 | | - resource_config |
925 | | - and resource_config.get("Type") == "AWS::Serverless::Function" |
926 | | - ): |
927 | | - properties = resource_config.get("Properties", {}) |
928 | | - if properties: |
929 | | - code_uri = properties.get("CodeUri", "") |
930 | | - if isinstance(code_uri, str): |
931 | | - code_uri = code_uri.rstrip("/") |
932 | | - code_dir = ( |
933 | | - code_uri.split("/")[-1] if "/" in code_uri else code_uri |
934 | | - ) |
935 | | - if code_dir == dir_name: |
936 | | - return resource_name |
| 879 | + with open(template_path, "r", encoding="utf-8") as f: |
| 880 | + lines = f.readlines() |
| 881 | + |
| 882 | + for i, line in enumerate(lines): |
| 883 | + # Look for CodeUri that matches our directory |
| 884 | + if "CodeUri:" in line: |
| 885 | + code_uri = ( |
| 886 | + line.split("CodeUri:")[-1].strip().strip("\"'").rstrip("/") |
| 887 | + ) |
| 888 | + code_dir = code_uri.split("/")[-1] if "/" in code_uri else code_uri |
| 889 | + |
| 890 | + if code_dir == dir_name: |
| 891 | + # Found matching CodeUri, now look backwards for the resource name |
| 892 | + # Look for AWS::Serverless::Function type first |
| 893 | + for j in range(i - 1, max(0, i - 50), -1): |
| 894 | + if "Type: AWS::Serverless::Function" in lines[j]: |
| 895 | + # Found the function type, now look backwards for resource name |
| 896 | + for k in range(j - 1, max(0, j - 10), -1): |
| 897 | + stripped = lines[k].strip() |
| 898 | + # Resource names are at the start of line and end with ':' |
| 899 | + if ( |
| 900 | + stripped |
| 901 | + and not stripped.startswith(" ") |
| 902 | + and stripped.endswith(":") |
| 903 | + ): |
| 904 | + return stripped.rstrip(":") |
| 905 | + break |
937 | 906 |
|
938 | 907 | return dir_name |
939 | 908 |
|
|
0 commit comments