Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
svpino committed May 24, 2023
1 parent c9384c3 commit be941f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 54 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,5 @@ dmypy.json

penguins/*.csv
penguins/*.py
penguins/code/inference.py
penguins/code/_repack_*
penguins/code/
mnist/dataset/
57 changes: 5 additions & 52 deletions penguins-cohort.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 64,
"id": "ed40d098-d553-4d56-b2eb-f80cec420ca5",
"metadata": {
"tags": []
Expand All @@ -2696,7 +2696,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting penguins/code/requirements.txt\n"
"Writing penguins/code/requirements.txt\n"
]
}
],
Expand Down Expand Up @@ -3022,59 +3022,13 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 63,
"id": "f9941979-c085-4ef9-8c66-908378d89a91",
"metadata": {
"tags": []
},
"outputs": [
{
"ename": "ClientError",
"evalue": "An error occurred (AccessDeniedException) when calling the GetFunction operation: User: arn:aws:sts::325223348818:assumed-role/AmazonSageMaker-ExecutionRole-20230312T160501/SageMaker is not authorized to perform: lambda:GetFunction on resource: arn:aws:lambda:us-east-1:325223348818:function:deploy_model because no identity-based policy allows the lambda:GetFunction action",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mClientError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-62-8a7be9ddd387>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mlambda_role\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcreate_lambda_role\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"lambda-pipeline-role\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m \u001b[0mcreate_lambda_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"deploy_model\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlambda_role\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-62-8a7be9ddd387>\u001b[0m in \u001b[0;36mcreate_lambda_function\u001b[0;34m(function_name, role_arn)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcreate_lambda_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfunction_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrole_arn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m response = lambda_client.get_function(\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mFunctionName\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfunction_name\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m )\n",
"\u001b[0;32m/usr/local/lib/python3.8/site-packages/botocore/client.py\u001b[0m in \u001b[0;36m_api_call\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 528\u001b[0m )\n\u001b[1;32m 529\u001b[0m \u001b[0;31m# The \"self\" in this scope is referring to the BaseClient.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 530\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_make_api_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moperation_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 531\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 532\u001b[0m \u001b[0m_api_call\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpy_operation_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/usr/local/lib/python3.8/site-packages/botocore/client.py\u001b[0m in \u001b[0;36m_make_api_call\u001b[0;34m(self, operation_name, api_params)\u001b[0m\n\u001b[1;32m 962\u001b[0m \u001b[0merror_code\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mparsed_response\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Error\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Code\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 963\u001b[0m \u001b[0merror_class\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexceptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_code\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0merror_code\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 964\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0merror_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparsed_response\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moperation_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 965\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 966\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mparsed_response\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mClientError\u001b[0m: An error occurred (AccessDeniedException) when calling the GetFunction operation: User: arn:aws:sts::325223348818:assumed-role/AmazonSageMaker-ExecutionRole-20230312T160501/SageMaker is not authorized to perform: lambda:GetFunction on resource: arn:aws:lambda:us-east-1:325223348818:function:deploy_model because no identity-based policy allows the lambda:GetFunction action"
]
}
],
"outputs": [],
"source": [
"import boto3\n",
"\n",
"lambda_client = boto3.client('lambda')\n",
"\n",
"def create_lambda_function(function_name, role_arn):\n",
" try:\n",
" response = lambda_client.get_function(\n",
" FunctionName=function_name\n",
" )\n",
" \n",
" lambda_client.update_function_code(\n",
" FunctionName=function_name,\n",
" ZipFile=zipped_code,\n",
" Publish=True\n",
" )\n",
"\n",
" print(f\"Lambda function {function_name} updated successfully.\")\n",
" \n",
" print(f\"Lambda function {function_name} already exists.\")\n",
" except lambda_client.exceptions.ResourceNotFoundException:\n",
" response = lambda_client.create_function(\n",
" FunctionName=function_name,\n",
" Runtime=\"python3.8\",\n",
" Role=role_arn,\n",
" Handler=\"lambda.lambda_handler\",\n",
" Code=str(PENGUINS_FOLDER / \"lambda.py\"),\n",
" )\n",
"\n",
" print(f\"Lambda function {function_name} created successfully.\")\n",
"\n",
"\n",
"def create_lambda_role(role_name):\n",
" try:\n",
" response = iam_client.create_role(\n",
Expand Down Expand Up @@ -3113,8 +3067,7 @@
" return response['Role']['Arn']\n",
" \n",
"\n",
"lambda_role = create_lambda_role(\"lambda-pipeline-role\")\n",
"create_lambda_function(\"deploy_model\", lambda_role)"
"lambda_role = create_lambda_role(\"lambda-pipeline-role\")"
]
},
{
Expand Down

0 comments on commit be941f2

Please sign in to comment.