Skip to content

Feature request: CodePipeline Lambda Event #5

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

Closed
jplock opened this issue May 2, 2021 · 9 comments
Closed

Feature request: CodePipeline Lambda Event #5

jplock opened this issue May 2, 2021 · 9 comments
Labels

Comments

@jplock
Copy link

jplock commented May 2, 2021

Is your feature request related to a problem? Please describe.

A CodePipeline data class for Lambda events with helper methods to use the embedded credentials to download an artifact from S3.

https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html#actions-invoke-lambda-function-json-event-example

Describe the solution you'd like

see above

Describe alternatives you've considered

Manually accessing the event

Additional context

@michaelbrewer
Copy link
Contributor

Cool, i will have a look. Is there any additional docs on the schema for this? I would assume their would some utils needed for this as well.

@jplock
Copy link
Author

jplock commented May 2, 2021

@michaelbrewer i haven’t seen any other docs beyond that page. There is sample python code on there as well.

@michaelbrewer
Copy link
Contributor

@jplock tracked down more docs :)

@michaelbrewer
Copy link
Contributor

michaelbrewer commented May 4, 2021

@michaelbrewer
Copy link
Contributor

@jplock @heitorlessa any insights to what kind of utility short cuts (like setting up the S3 session) to add to the event type :)

@jplock
Copy link
Author

jplock commented May 4, 2021

@michaelbrewer how about something like:

def get_artifact(self, artifact_name: str, filename: str) -> Optional[str]:
  s3 = boto3.client(
    "s3",
    aws_access_key_id=self.data.artifact_credentials.access_key_id,
    aws_secret_access_key=self.data.artifact_credentials.secret_access_key,
    aws_session_token=self.data.artifact_credentials.session_token
  )

  for artifact in self.data.input_artifacts:
    if artifact.name == artifact_name:
      bucket = artifact.location.s3_location.bucket_name
      key = artifact.location.s3_location.key
    
      with tempfile.NamedTemporaryFile() as tmp_file:
        s3.download_file(bucket, key, tmp_file.name)
        with zipfile.ZipFile(tmp_file.name, 'r') as zip:
          return zip.read(filename)

  return None
  

@michaelbrewer
Copy link
Contributor

@jplock zip.read returns bytes and Cloudformation create_stack and update_stack expects a string for the TemplateBody.

So i might have to add a decode("UTF-8") to this.

@heitorlessa heitorlessa transferred this issue from aws-powertools/powertools-lambda-python May 13, 2021
@michaelbrewer
Copy link
Contributor

@jplock this has been officially released now: CodePipeline Job

@jplock
Copy link
Author

jplock commented May 18, 2021

Thank you for pushing this through @michaelbrewer !

@jplock jplock closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants