Search code examples
javaamazon-s3aws-lambdaaws-code-deployaws-codepipeline

How to automatically deploy a jar from s3 to aws lambda?


I want to automatically deploy a jar to aws-lamda whenever there is any change in the version of the jar in s3 bucket.

For example: There is one S3 bucket say lambdadeploytestand a Lamda functionname autoDeployTest. I have stored an object test.jar in lambdadeploytest.

Whenever there is I upload a new version of the object test.jar, test.jar will be automatically deployed to autoDeployTest lambda function.


Solution

  • You can do that with a lambda function ...
    At high level the steps are

    • create a lambda function that will download the test.jar and use the jar to create / update the autoDeployTest lambda function.

    • configure your new lambda function to be triggered when test.jar is modified on S3

    • configure the new lambda function with permissions to read your S3 bucket and to deploy code on Lambda.

    You can follow this tutorial to create a lambda function that would be triggered by S3 events. This is the Lambda API your lambda function can call to update autodeployTest code.

    Pseudo Code would be like this :

    read JSON event object to get the bucket name and object name (bucket_name, test.jar)
    
    download a copy of the object (test.jar) to the lambda container 
    
    (do additional check on the jar file if required) 
    
    call Lambda's UpdateFunctionCode to update autoDeployTest function code with the jar.