Skip to content

Commit bb15064

Browse files
committed
Revert "fixing lambda execution errors"
This reverts commit a64cf74.
1 parent a64cf74 commit bb15064

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

iac/iac_stack.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,34 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
2828

2929
ecr_repository = ecr.Repository.from_repository_name(self, "MLOpsRepo", "jackpot-optimizer")
3030

31-
# Use existing SageMaker roles for all services (simpler and more reliable)
32-
sagemaker_execution_role_arn = f"arn:aws:iam::{self.account}:role/AmazonSageMaker-ExecutionRole-20250811T230696"
33-
31+
# Use existing roles - you'll need to create these manually first
32+
# Replace these ARNs with your actual role ARNs
3433
sagemaker_role = iam.Role.from_role_arn(self, "SageMakerExecutionRole",
35-
role_arn=sagemaker_execution_role_arn
34+
role_arn=f"arn:aws:iam::{self.account}:role/SageMakerExecutionRole"
3635
)
3736

3837
lambda_role = iam.Role.from_role_arn(self, "LambdaExecutionRole",
39-
role_arn=sagemaker_execution_role_arn
38+
role_arn=f"arn:aws:iam::{self.account}:role/LambdaExecutionRole"
4039
)
4140

4241
optimizer_lambda = _lambda.DockerImageFunction(self, "OptimizerFunction",
43-
code=_lambda.DockerImageCode.from_ecr(ecr_repository, tag_or_digest=image_tag),
42+
code=_lambda.DockerImageCode.from_ecr(ecr_repository,
43+
tag_or_digest=image_tag,
44+
cmd=["lambda_handler.optimizer.handler.lambda_handler"]
45+
),
4446
memory_size=1024,
4547
timeout=Duration.minutes(5),
4648
environment={"ARTIFACT_BUCKET": artifact_bucket.bucket_name},
4749
role=lambda_role
4850
)
49-
50-
# Grant Lambda additional permissions if needed
51-
optimizer_lambda.add_to_role_policy(iam.PolicyStatement(
52-
actions=["sagemaker:DescribeTrainingJob"],
53-
resources=["*"]
54-
))
5551

5652
recommendation_topic = sns.Topic(self, "RecommendationTopic")
5753
recommendation_topic.add_subscription(subscriptions.EmailSubscription("subhojit20@gmail.com"))
5854

5955
# --- 2. Step Functions Workflow Definition ---
6056

6157
train_task = sfn_tasks.SageMakerCreateTrainingJob(self, "TrainSalesModel",
62-
# Remove training_job_name - let CDK auto-generate a compliant one
58+
training_job_name=sfn.JsonPath.string_at("$$.Execution.Name"),
6359
role=sagemaker_role,
6460
algorithm_specification=sfn_tasks.AlgorithmSpecification(
6561
training_image=sfn_tasks.DockerImage.from_registry(
@@ -90,10 +86,18 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
9086

9187
optimize_task = sfn_tasks.LambdaInvoke(self, "OptimizeJackpot",
9288
lambda_function=optimizer_lambda,
89+
# payload=sfn.TaskInput.from_object({
90+
# "model_s3_path": sfn.JsonPath.string_at("$.Model.ModelArtifacts.S3ModelArtifacts"),
91+
# "country": "england"
92+
# }),
9393
payload=sfn.TaskInput.from_object({
94-
# Pass the training job ARN - let Lambda handle getting the model artifacts
95-
"training_job_arn": sfn.JsonPath.string_at("$.Model.TrainingJobArn"),
96-
"country": "england"
94+
# Construct the S3 path manually based on your output configuration
95+
"model_s3_path": sfn.JsonPath.format(
96+
"s3://{}/models/{}/output/model.tar.gz",
97+
artifact_bucket.bucket_name,
98+
sfn.JsonPath.string_at("$$.Execution.Name")
99+
),
100+
"country": "england"
97101
}),
98102
result_path="$.Recommendation"
99103
)
@@ -113,9 +117,9 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
113117
train_task.add_catch(failure_state, result_path="$.error-info")
114118
optimize_task.add_catch(failure_state, result_path="$.error-info")
115119

116-
# Use the same SageMaker role for Step Functions
120+
# Use existing Step Functions role
117121
step_functions_role = iam.Role.from_role_arn(self, "StepFunctionsRole",
118-
role_arn=sagemaker_execution_role_arn
122+
role_arn=f"arn:aws:iam::{self.account}:role/StepFunctionsExecutionRole"
119123
)
120124

121125
state_machine = sfn.StateMachine(self, "JackpotStateMachine",

0 commit comments

Comments
 (0)