Search code examples
amazon-web-servicesaws-lambdaaws-codepipelineaws-codebuildaws-codecommit

Inputs to AWS lambda functions in a pipeline



I am new to AWS and i'm trying to set a testing environment using its services, as follows:
I set a pipeline (with AWS code pipeline) that is triggered with every new push to my online repository (AWS code commit).
Than, I use AWS code build to run unit tests on my project (in python). I can see the tests results with AWS cloud watch (in the output logs from AWS code build service).
Afterwards, I want to set a lambda function that parses the logs and produces a summary of the unit tests results to send to my email via AWS SES.

Unfortunately, I can't understand how to transfer the AWS code build output logs as an input to a lambda function. I was only able to use the default "event" struct defined in the lambda function, that is triggered after every build of the code, and parse its partial data (I managed to save the logs in S3 but I don't know if and how I can use them).

Moreover, I want to send the tests summary to specific emails depending on the user that commited the push to the repository. How can I get the user information that commited the push and insert it, for example, to a lambda function that will identify the user and send the tests summary to its email? is there an easier way to build my testing environment?

thanks in advance!

Solution

  • You can configure the AWS Codebuild jobs to send the logs to S3 bucket as shown in the below snippet

    enter image description here

    And from there you can configure your S3 Events Notification and hook your lambda to that.

    As far as I read the docs there are three methods of authentication to codecommit and only one provide a related solution to getting the email address of the code committer via sessions tags.

    • HTTPs( Git credentials IAM users doesnt have email address)
    • SSH ( again no email address)
    • HTTPS Git Remote Commit

    So you are left with Authorization based on CodeCommit tags which is recommended for

    If you want to connect to CodeCommit using a root account, federated access, or temporary credentials, you should set up access using git-remote-codecommit

    You need to connect pieces together here Monitoring CodeCommit events in Amazon EventBridge and Amazon CloudWatch Events

    Because as soon as the code commit's event gets triggered with the information( provided you are using GRC), you need to wait for the code build job finishes which puts your jobs' logs to s3, and eventually your lambda gets triggered.

    I will use AWS Step Function Parallel Workflow for this where the event from the codecommit triggers the lambda and then Step function Code Build works do the rest for me. But this is just a choice, you handle the integration via lambdas as well.