{"id":18256811,"url":"https://github.com/trojan295/aws-sam-lambda-notes-example-app","last_synced_at":"2025-06-30T09:37:38.120Z","repository":{"id":115412930,"uuid":"292220749","full_name":"Trojan295/aws-sam-lambda-notes-example-app","owner":"Trojan295","description":"An example Vue.js + Golang based Lambda backend app deployed using AWS SAM","archived":false,"fork":false,"pushed_at":"2020-09-04T09:51:30.000Z","size":154,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T22:32:25.314Z","etag":null,"topics":["codedeploy","hook-functions","lambda","lambda-deployment","rollback"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Trojan295.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-02T08:12:45.000Z","updated_at":"2020-09-16T12:24:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"caa36602-b961-45ce-bee6-ca8fff2ee2cc","html_url":"https://github.com/Trojan295/aws-sam-lambda-notes-example-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Trojan295/aws-sam-lambda-notes-example-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trojan295%2Faws-sam-lambda-notes-example-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trojan295%2Faws-sam-lambda-notes-example-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trojan295%2Faws-sam-lambda-notes-example-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trojan295%2Faws-sam-lambda-notes-example-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Trojan295","download_url":"https://codeload.github.com/Trojan295/aws-sam-lambda-notes-example-app/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trojan295%2Faws-sam-lambda-notes-example-app/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262748896,"owners_count":23358297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codedeploy","hook-functions","lambda","lambda-deployment","rollback"],"created_at":"2024-11-05T10:23:46.257Z","updated_at":"2025-06-30T09:37:38.082Z","avatar_url":"https://github.com/Trojan295.png","language":"Go","readme":"# AWS Serverless Application Model Lambda Notes example application\n\n## How to run it\n\n1. Deploy the SAM package\n```\ncd backend\nmake deploy\n```\n2. Setup the repository in the created AWS Amplify app. You can use the AWS Console, so it will guide you through this\n3. Browse to the created Amplify app webpage\n\n## Lambda CodeDeploy deployments\n\nSAM uses Lambda aliases to perform canary and linear deployments. This allows to gradually shift traffic to the new version and rollback in case errors are appearing.\n\nThis example shows two options how to perform checks on a new Lambda deployment and rollback it in case of failures:\n\n1. Rollback triggered by Cloudwatch Alarms in the `AllowTraffic` stage. The following setup triggers a rollback of the deployment in case there are more that 5% of 5xx errors for 1 minute on the API Gateway during traffic shifting. Note that it means 5% of all Lambda calls and as SAM uses Lambda weighted alias you have to take it into account. For ex. if using `Canary10Percent5Minutes`, then 10% of the traffic is directed to the new Lambda, so with 5% error rate, 50% of the traffic to the new Lambda would need to error to trigger the rollback\n```\n  NotesApiServerErrorAlarm:\n    Type: AWS::CloudWatch::Alarm\n    Properties:\n      AlarmName: NotesApiServerErrorAlarm\n      EvaluationPeriods: 1\n      Metrics:\n      - Id: m1\n        MetricStat:\n          Metric:\n            Dimensions:\n              - Name: ApiName\n                Value: !Ref ApiName\n            MetricName: 5XXError\n            Namespace: AWS/ApiGateway\n          Period: !!int 60\n          Stat: Average\n      ComparisonOperator: GreaterThanThreshold\n      Threshold: 0.05\n      TreatMissingData: notBreaching\n\n  AddNote:\n    Type: AWS::Serverless::Function\n    Properties:\n      DeploymentPreference:\n        Type: Canary10Percent5Minutes\n        Alarms:\n          - !Ref NotesApiServerErrorAlarm\n      [...]\n```\n\n2. Hook triggered rollback. You can call a Lambda function in the `BeforeAllowTraffic` or `AfterAllowTraffic` stage, to verify the new Lambda function or run final tests. You muist call the `codedeploy:PutLifecycleEventHookExecutionStatus` API call to tell CodeDeploy about the status of the deployment. CodeDeploy will fail the deployment after 1 hour, if no call is made\n```\n  GetNotes:\n    Type: AWS::Serverless::Function\n    Properties:\n      DeploymentPreference:\n        Hooks:\n          PostTraffic: !Ref ValidateAPI\n      [...]\n\n  ValidateAPI:\n    Type: AWS::Serverless::Function\n    Properties:\n      FunctionName: CodeDeployHook_ValidateAPI\n      Policies:\n        - Version: '2012-10-17' \n          Statement:\n            - Effect: Allow\n              Action:\n                - codedeploy:PutLifecycleEventHookExecutionStatus \n              Resource:\n                !Sub 'arn:aws:codedeploy:${AWS::Region}:${AWS::AccountId}:deploymentgroup:${ServerlessDeploymentApplication}/*'\n      [...]\n```\nNote that the hook Lambda function needs the IAM permissions to call the AWS API\n\n## Notes about SAM\n\n1. Hook functions must start with prefix \"CodeDeployHook_\" or you have to provide an custom IAM role for the CodeDeploy in `DeploymentPreference`\n2. The hook functions must response to AWS API, if the hook passed or failed. CodeDeploy timeouts after 1 hour waiting resulting in a fail. You need to provide the policy to those functions, so they can all the API\n3. The `Alarms` in `DeploymentPreference` can be used to rollback the deployment on Cloudwatch Alarm. The AWS docs suggest the other way - that they are triggered by a failed deployment","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrojan295%2Faws-sam-lambda-notes-example-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrojan295%2Faws-sam-lambda-notes-example-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrojan295%2Faws-sam-lambda-notes-example-app/lists"}