{"id":21765804,"url":"https://github.com/sharinas/aws-sam-and-github-actions","last_synced_at":"2025-03-21T05:22:08.564Z","repository":{"id":48344047,"uuid":"390872206","full_name":"SharinaS/aws-sam-and-github-actions","owner":"SharinaS","description":"A demo project on using AWS SAM to create a serverless application to deploy into AWS with automatic deployments using a pipeline setup by GitHub Actions' setup-sam. ","archived":false,"fork":false,"pushed_at":"2021-07-30T23:48:15.000Z","size":207,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T01:49:22.259Z","etag":null,"topics":["aws-sam","aws-sam-cli","ci-cd","devops","github-actions","pipelines","python3","serverless-architectures"],"latest_commit_sha":null,"homepage":"","language":"Python","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/SharinaS.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}},"created_at":"2021-07-29T23:14:04.000Z","updated_at":"2021-07-30T23:51:58.000Z","dependencies_parsed_at":"2022-09-14T15:20:29.590Z","dependency_job_id":null,"html_url":"https://github.com/SharinaS/aws-sam-and-github-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SharinaS%2Faws-sam-and-github-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SharinaS%2Faws-sam-and-github-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SharinaS%2Faws-sam-and-github-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SharinaS%2Faws-sam-and-github-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SharinaS","download_url":"https://codeload.github.com/SharinaS/aws-sam-and-github-actions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244741169,"owners_count":20502223,"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":["aws-sam","aws-sam-cli","ci-cd","devops","github-actions","pipelines","python3","serverless-architectures"],"created_at":"2024-11-26T13:14:02.802Z","updated_at":"2025-03-21T05:22:08.542Z","avatar_url":"https://github.com/SharinaS.png","language":"Python","readme":"# AWS SAM and GitHub Actions\n\nAWS SAM is used to create a small serverless application, a single AWS Lambda Python 3.8 function invoked by an Amazon API Gateway endpoint. Once the code is pushed to GitHub, a GitHub Actions workflow triggers a GitHub CI/CD pipeline to build and deploy the code to the targeted AWS account.\n\nAWS blog posts on this topic:\n\n* https://aws.amazon.com/blogs/compute/using-github-actions-to-deploy-serverless-applications/\n\n## Definitions\n\n### GitHub Actions Runner\n\nThe application that runs a job from a GitHub Actions workflow. A GitHub hosted runner is a virtual machine hosted by GitHub with the runner application installed.\n\n## Prerequisites\n\n* AWS CLI\n* AWS SAM CLI\n* An Amazon S3 bucket in the working AWS account to store the deployment build package\n\n## Steps Taken\n\n### GitHub Repo\n\nCreated this GitHub repo and cloned it locally.\n\n### Make a SAM application\n\nAWS SAM has several quick-start templates to help create an application, one of which I used for this project. It's a hello-world python application. [More on this here](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/serverlessrepo-quick-start.html).\n\nIf you want a different runtime than python 3.8, run `aws sam init -h` for all the things you can choose from.\n\nRun this command at the root of the cloned repository directory to create the application, changing the `-n` value to the name you want for your SAM application. Choose zip when asked if you want a zip or an image.\n\n```bash\nsam init -r python3.8 -n github-actions-with-aws-sam --app-template \"hello-world\"\n```\n\n## Check that Things are Wired Up Correctly (Locally)\n\nAWS SAM allows for testing the applications locally, since it has a default event in `events/event.json`.\n\n### Test the Lambda\nInvoke the Lambda function by navigating into the root of the SAM app directory and passing the default event:\n\n```bash\nsam local invoke HelloWorldFunction -e events/event.json\n```\n\nNote that `HelloWorldFunction` is the logical id of the lambda resource found in the `template.yaml` file at the root of the SAM app.\n\nYou should get a 200 status code and a `hello world`.\n\n### Test the API Gateway\n\nStart the API locally with:\n\n```bash\nsam local start-api\n```\n\nThis tells AWS SAM to launch a Docker container with a mock API Gateway endpoint listening on localhost:3000.\n\nUse curl to call the hello API (in a second terminal tab) or paste the URL into a browser window. You should see the the output of HTML either way.\n\n```bash\ncurl http://127.0.0.1:3000/hello\n```\n\nThe `/hello` page is defined by the template file, which defines the HelloWorldEvent as having as a path property of `/hello`.\n\n### Update the Lambda Code\n\nThe Lambda function initially had a simple JSON output of `{hello world}` from a `\"body\": json.dumps...` after being created by the SAM init command. I updated the Lambda to have a return of HTML instead.\n\n#TODO: Set up the lambda to read an html file stored outside of the lambda\nhtmlFile = open('content/html-file.html', 'r')\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharinas%2Faws-sam-and-github-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsharinas%2Faws-sam-and-github-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsharinas%2Faws-sam-and-github-actions/lists"}