DEV Community

MJ
MJ

Posted on

Key Takeaway of Publishing Lambda Function using Serverless Application Repository (SAR)

The Serverless Application Repository (SAR) is an easy way for the developers to find and deploy existing application in the AWS Cloud. For more info, refer to official guide.

One of more popular use cases now is to share the Lambda function with the community. After being published on the AWS SAR, anyone can just deploy the Lambda function directly into their account with just a few clicks.

There are few ways of publishing on SAR:

  • AWS Management Console
  • AWS SAM command line interface (AWS SAM CLI)
  • AWS SDKs to upload the code.

The easy way is to do it through the Management Console and here are some key take-aways:

  • Only applications created in us-east-1 or us-east-2 allows sharing/visible to the public. Applications created in other regions can be shared privately using accounts number. Semantic version is also required for publicly published application.

  • Ensure that you have created a bucket to host your Lambda code artifact (archive.zip) and amended the bucket policy with the following:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service":  "serverlessrepo.amazonaws.com"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<your-bucket-name>/*"
        }
    ]
}
  • Description and License info on the SAR is compulsory.

  • The most important one is to create a valid AWS Serverless Application Model (AWS SAM) that define the AWS resources. The full documentation is here. But, these are some samples on my Github:
    -- Example 1 - This contains addition of multiple role policies required for the Lambda. Parameters are also used in this examples to take in inputs for the SAR application.
    -- Example 2 - This contains creation of a S3 Bucket and adds listened Events to the objects created in the S3 Bucket.
    -- Example 3 - This contains creation of Role and RolePolicy resources for attached to the Lambda function. DependsOn is also used to ensure the resources are created in correct order.

  • Once your have published a new version of the application on SAR, the users need to redeploy the application with latest version. Otherwise, they will remain on the older version.

  • Once an application is deployed using SAR, you can check the status from the Cloud Formation's Stacks console. You can remove the application from there and check if there is any issues with the deployment.

Reference:

Top comments (0)