[{"data":1,"prerenderedAt":66},["ShallowReactive",2],{"content-testing-python-starter-2-project-setup":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":12,"contributorPaths":13,"menuType":16,"contentName":17,"slug":18,"readingTime":19,"menu":20,"nextDocItem":36,"previousDocItem":24},"\u003Cp>This application creates several AWS resources, including a Lambda function and an API Gateway. We defined these resources in the \u003Ccode>template.yaml\u003C\u002Fcode> file in this project. This project includes the following files and folders:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>src - Code for the application&#39;s Lambda function.\u003C\u002Fli>\n\u003Cli>events - synthetic events that you can use to invoke the function.\u003C\u002Fli>\n\u003Cli>tests - Unit and integration tests for the application code. \u003C\u002Fli>\n\u003Cli>template.yaml - A template that defines the application&#39;s AWS resources.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>Prerequisites\u003C\u002Fh2>\n\u003Cp>The SAM CLI extends the AWS CLI that adds functionality for building and testing serverless applications. It contains features for building your application locally, deploying it to AWS, and emulating AWS services locally to support automated unit tests.  \u003C\u002Fp>\n\u003Cp>To use the SAM CLI, you need the following tools.\u003C\u002Fp>\n\u003Cul>\n\u003Cli>SAM CLI - \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-sam-cli-install.html\">Install the SAM CLI\u003C\u002Fa>\u003C\u002Fli>\n\u003Cli>Python 3 - \u003Ca href=\"https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F\">Install Python 3\u003C\u002Fa>\u003C\u002Fli>\n\u003Cli>Docker - \u003Ca href=\"https:\u002F\u002Fhub.docker.com\u002Fsearch\u002F?type=edition&offering=community\">Install Docker community edition\u003C\u002Fa>\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>Build and deploy with the SAM CLI\u003C\u002Fh2>\n\u003Cp>Use the following command to build your application locally: \u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-bash\"># build your application locally using a container\n sam build --use-container\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>The SAM CLI installs dependencies defined in \u003Ccode>src\u002Frequirements.txt\u003C\u002Fcode>, creates a deployment package, and saves it in the \u003Ccode>.aws-sam\u002Fbuild\u003C\u002Fcode> folder. \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-building.html\">Read the documentation\u003C\u002Fa>.\u003C\u002Fp>\n\u003Cp>Use the following command to deploy your application package to AWS: \u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-bash\"># deploy your application to the AWS cloud \n sam deploy --guided\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>After running this command you will receive a series of prompts:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cp>\u003Cstrong>Stack Name\u003C\u002Fstrong>: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. Use \u003Ccode>apigw-lambda\u003C\u002Fcode> as the stack name for this project.\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\u003Cp>\u003Cstrong>AWS Region\u003C\u002Fstrong>: The AWS region you want to deploy your app to.\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\u003Cp>\u003Cstrong>Confirm changes before deploy\u003C\u002Fstrong>: If set to yes, SAM CLI shows you any change sets for manual review before deployment. If set to no, the AWS SAM CLI will automatically deploy application changes.\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\u003Cp>\u003Cstrong>Allow SAM CLI IAM role creation\u003C\u002Fstrong>: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, SAM CLI scopes these down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or changes IAM roles, the \u003Ccode>CAPABILITY_IAM\u003C\u002Fcode> value for \u003Ccode>capabilities\u003C\u002Fcode> must be provided. If you don&#39;t provide permission through this prompt, you must explicitly pass \u003Ccode>--capabilities CAPABILITY_IAM\u003C\u002Fcode> to the \u003Ccode>sam deploy\u003C\u002Fcode> command.\u003C\u002Fp>\n\u003C\u002Fli>\n\u003Cli>\u003Cp>\u003Cstrong>Save arguments to samconfig.toml\u003C\u002Fstrong>: If set to yes, SAM CLI saves your choices to a configuration file inside the project, so that in the future you can just re-run \u003Ccode>sam deploy\u003C\u002Fcode> without parameters to deploy changes to your application.\u003C\u002Fp>\n\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>You will see several output values displayed after the deployment. Take note of the API Gateway Endpoint URL and the function name of the Lambda function (it is the last part of the generated ARN value) . On subsequent deploys you can run \u003Ccode>sam deploy\u003C\u002Fcode> without the \u003Ccode>--guided\u003C\u002Fcode> flag. \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-deploying.html\">Read the documentation\u003C\u002Fa>.\u003C\u002Fp>\n",{"title":6,"order":7,"callout":8},"Project Setup",2,{"title":9,"description":10,"link":11},"Check out other starter guides","Do you prefer to learn in another language? We also have starter guides in Java, TypeScript, and .NET.","https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-test-samples\u002F","This application creates several AWS resources, including a Lambda function and an API Gateway. We defined these resources in the `template.yaml` file in this project. This project includes the following files and folders:\n\n- src - Code for the application's Lambda function.\n- events - synthetic events that you can use to invoke the function.\n- tests - Unit and integration tests for the application code. \n- template.yaml - A template that defines the application's AWS resources.\n\n## Prerequisites\nThe SAM CLI extends the AWS CLI that adds functionality for building and testing serverless applications. It contains features for building your application locally, deploying it to AWS, and emulating AWS services locally to support automated unit tests.  \n\nTo use the SAM CLI, you need the following tools.\n\n* SAM CLI - [Install the SAM CLI](https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-sam-cli-install.html)\n* Python 3 - [Install Python 3](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F)\n* Docker - [Install Docker community edition](https:\u002F\u002Fhub.docker.com\u002Fsearch\u002F?type=edition&offering=community)\n\n## Build and deploy with the SAM CLI\nUse the following command to build your application locally: \n\n```bash\n# build your application locally using a container\n sam build --use-container\n```\nThe SAM CLI installs dependencies defined in `src\u002Frequirements.txt`, creates a deployment package, and saves it in the `.aws-sam\u002Fbuild` folder. [Read the documentation](https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-building.html).\n\nUse the following command to deploy your application package to AWS: \n\n``` bash\n# deploy your application to the AWS cloud \n sam deploy --guided\n```\n\nAfter running this command you will receive a series of prompts:\n\n* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. Use `apigw-lambda` as the stack name for this project.\n* **AWS Region**: The AWS region you want to deploy your app to.\n* **Confirm changes before deploy**: If set to yes, SAM CLI shows you any change sets for manual review before deployment. If set to no, the AWS SAM CLI will automatically deploy application changes.\n* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, SAM CLI scopes these down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or changes IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If you don't provide permission through this prompt, you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command.\n\n* **Save arguments to samconfig.toml**: If set to yes, SAM CLI saves your choices to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application.\n\nYou will see several output values displayed after the deployment. Take note of the API Gateway Endpoint URL and the function name of the Lambda function (it is the last part of the generated ARN value) . On subsequent deploys you can run `sam deploy` without the `--guided` flag. [Read the documentation](https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fserverless-deploying.html).",[14,15],"content\u002Fcontributors\u002Fdan-fox.json","content\u002Fcontributors\u002Frohan-mehta.json","LIST","Python Test Samples Starter Project","\u002Fcontent\u002Ftesting\u002Fpython-starter\u002F2-project-setup","3 min",[21],{"title":22,"content":23},"Testing Guide",[24,32,36,44,52,59],{"title":25,"order":26,"callout":27,"time":28,"path":29,"id":30,"link":31},"Introduction",1,{"title":9,"description":10,"link":11},"1 min","1-introduction","1-introduction.md","\u002Fcontent\u002Ftesting\u002Fpython-starter\u002F1-introduction",{"title":6,"order":7,"callout":33,"time":19,"path":34,"id":35,"link":18},{"title":9,"description":10,"link":11},"2-project-setup","2-project-setup.md",{"title":37,"order":38,"callout":39,"time":40,"path":41,"id":42,"link":43},"Local Testing",3,{"title":9,"description":10,"link":11},"4 min","3-local-testing","3-local-testing.md","\u002Fcontent\u002Ftesting\u002Fpython-starter\u002F3-local-testing",{"title":45,"order":46,"callout":47,"time":48,"path":49,"id":50,"link":51},"Testing in the Cloud",4,{"title":9,"description":10,"link":11},"2 min","4-testing-in-the-cloud","4-testing-in-the-cloud.md","\u002Fcontent\u002Ftesting\u002Fpython-starter\u002F4-testing-in-the-cloud",{"title":53,"order":54,"callout":55,"time":48,"path":56,"id":57,"link":58},"Observability in Testing",5,{"title":9,"description":10,"link":11},"5-observability-in-testing","5-observability-in-testing.md","\u002Fcontent\u002Ftesting\u002Fpython-starter\u002F5-observability-in-testing",{"title":60,"order":61,"callout":62,"time":28,"path":63,"id":64,"link":65},"Cleanup",6,{"title":9,"description":10,"link":11},"6-cleanup","6-cleanup.md","\u002Fcontent\u002Ftesting\u002Fpython-starter\u002F6-cleanup",1792578875012]