Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stepfunctions-tasks): missing permissions for running tasks on ecs #27891

Merged
merged 10 commits into from
Feb 12, 2024

Conversation

msambol
Copy link
Contributor

@msambol msambol commented Nov 8, 2023

While working on #27803, I noticed the integration tests for aws-stepfunctions-tasks/ecs were not fully working (they deployed but the state machines did not run successfully). This PR addresses two issues:

  1. Missing permissions for ecs:RunTask on the task definition version.
sfn-role
  1. The sample container was from a Lambda image. This resulted in the following error: entrypoint requires the handler name to be the first argument. I changed the image to docker/library/python:3.12.

These changes result in the successful execution of all four state machines in aws-stepfunctions-tasks/ecs.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added admired-contributor [Pilot] contributed between 13-24 PRs to the CDK p2 labels Nov 8, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team November 8, 2023 15:17
CMD python3 index.py
FROM --platform=x86-64 public.ecr.aws/docker/library/python:3.12
ADD index.py .
CMD [ "python3", "./index.py" ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed --platform=x86-64 since I am building on a Mac M2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing the image have you tried changing CMD:

CMD [ "index.handler" ]

and defining a handler function in index.py:

import os
import print

def handler(event, context):
    print('Hello from ECS!')
    pprint.pprint(dict(os.environ))

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try that but didn't spend a bunch of time on it. I can revisit.. but my thinking is, why is it a Lambda image when this is running on ECS and not in Lambda?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks for clarifying.

resources: [this.getTaskDefinitionFamilyArn()],
resources: [
this.getTaskDefinitionFamilyArn(),
`${this.getTaskDefinitionFamilyArn()}:*`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drawing attention to the bits that add permission to run versions of the task definition.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 9, 2023
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Some minor comments and a note on the Docker image change.

CMD python3 index.py
FROM --platform=x86-64 public.ecr.aws/docker/library/python:3.12
ADD index.py .
CMD [ "python3", "./index.py" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing the image have you tried changing CMD:

CMD [ "index.handler" ]

and defining a handler function in index.py:

import os
import print

def handler(event, context):
    print('Hello from ECS!')
    pprint.pprint(dict(os.environ))

?

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 9, 2023
CMD python3 index.py
FROM --platform=x86-64 public.ecr.aws/docker/library/python:3.12
ADD index.py .
CMD [ "python3", "./index.py" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks for clarifying.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Nov 10, 2023
@vinayak-kukreja vinayak-kukreja self-assigned this Dec 7, 2023
Copy link
Contributor

@vinayak-kukreja vinayak-kukreja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @msambol , this is great. Just a clarification comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me why some of these were removed?

And if we can remove --platform=x86-64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need some of these commands in the Dockerfile.

I needed --platform=x86-64 because I am building on an M2 and got an architecture mismatch. Unless I'm doing something wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with Docker but I'm also concerned with this. What about other users who are not on an M2 but on a computer incompatible with this platform? Maybe @mrgrain can weigh in further because I'm not well-versed myself in Docker stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrgrain Have some time to look at this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msambol What is the exact error you are getting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrgrain I'm not sure if I was doing something wrong or something changed, but it's working now without "platform" 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrgrain wait... I think this is still an issue. I get exec /usr/local/bin/python3: exec format error when I run the task without --platform=linux/amd64. Let me keep testing..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrgrain If I don't use --platform=linux/amd64, I get the following error when the task runs: exec /usr/local/bin/python3: exec format error. Similar here: #28898.

@msambol
Copy link
Contributor Author

msambol commented Dec 16, 2023

@vinayak-kukreja Any additional feedback on this?

@msambol
Copy link
Contributor Author

msambol commented Jan 24, 2024

@mrgrain Have time for another look at this one ?

@msambol
Copy link
Contributor Author

msambol commented Feb 11, 2024

@mrgrain Mind taking another look here?

Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and sorry for the delay @msambol

Copy link
Contributor

mergify bot commented Feb 12, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 12, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: a9bc264
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 683d595 into aws:main Feb 12, 2024
12 checks passed
Copy link
Contributor

mergify bot commented Feb 12, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

GavinZZ pushed a commit that referenced this pull request Feb 22, 2024
#27891)

While working on [#27803](#27803), I noticed the integration tests for `aws-stepfunctions-tasks/ecs` were not fully working (they deployed but the state machines did not run successfully). This PR addresses two issues:

1. Missing permissions for `ecs:RunTask` on the task definition version.
<img width="1587" alt="sfn-role" src="https://github.com/aws/aws-cdk/assets/3310356/13a0d402-8cbb-4852-9708-290f3a3b6711">

2. The sample container was from a Lambda image. This resulted in the following error: `entrypoint requires the handler name to be the first argument`. I changed the image to `docker/library/python:3.12`.

These changes result in the successful execution of all four state machines in `aws-stepfunctions-tasks/ecs`.


----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
akash1810 added a commit to guardian/cdk that referenced this pull request Mar 14, 2024
Updates for the changes introduced in AWS CDK v2.128.0.

See:
  - https://github.com/aws/aws-cdk/releases/tag/v2.128.0
  - aws/aws-cdk#27891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants