diff --git a/DevOps/AWS/Developing_AWS_projects_locally.md b/DevOps/AWS/Developing_AWS_projects_locally.md deleted file mode 100644 index 49eeadb..0000000 --- a/DevOps/AWS/Developing_AWS_projects_locally.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -categories: - - DevOps -tags: [AWS] ---- - -# Developing AWS projects locally - -To develop AWS projects locally the following core tools can be used to set up a local development environment that simulates AWS services: - -- AWS CLI - - Interact with AWS services from your local machine -- AWS SDK - - Integrate AWS services into your given programming language and application code -- [AWS SAM](/DevOps/AWS/AWS_SAM.md) diff --git a/DevOps/AWS/AWS_SAM.md b/DevOps/AWS/SAM/AWS_SAM.md similarity index 79% rename from DevOps/AWS/AWS_SAM.md rename to DevOps/AWS/SAM/AWS_SAM.md index 9d091a9..3749405 100644 --- a/DevOps/AWS/AWS_SAM.md +++ b/DevOps/AWS/SAM/AWS_SAM.md @@ -191,6 +191,49 @@ The build directory is `.aws-sam/build/`. There will be a subdirectory for each As noted, CloudFront handles the deployment of the application. It can only receive one file as an input. The packaging process consists in creating that single file. -The packaging proces will first archive all of the project artefacts into a zip file and then upload that to [S3](/DevOps/AWS/AWS_S3.md). +The packaging proces will first archive all of the project artefacts into a zip file and then upload that to [S3](/DevOps/AWS/AWS_S3.md). A reference to this S3 entity is then provided to CloudFormation. ![](/_img/s3-package-again.svg) + +The command is as follows: + +```sh +sam package + --template-file template.yaml + --output-template-file pkg.yml + --region eu-west-1 +``` + +This will automatically create a hashed bucket name for you in S3 (I have tried to add my own naming but it doesn't comply.) + +### Local development with Docker + +In order to work with your application locally without actually sending requests to AWS and using credit, you can run a local instance. + +See [Local AWS Development with SAM](/DevOps/AWS/SAM/Local_AWS_development_with_SAM.md). + +### Deploy + +Once you have packaged the app you can deploy with `sam deploy --guided`. This will talk you through the defaults and will deploy the package to CloudFormation. In CloudFormation each individual project is called a **stack**. + +If we then go to Cloud Formation we will see the deployed application. + +![](/_img/cloud-formation-stack.png) + +## Call the endpoint + +If we now go to the Lambda console, we will see our function listed, and the API Gateway endpoint under `triggers`: + +![](/_img/gateway-trigger.png) + +We can then call this from Postman to check everything is working as it should: + +![](/_img/postman-aws-output.png) + +## Clean up and erase the stack + +We can delete the stack and remove all the resources we have created with a single CLI method: + +```sh +aws cloudformation delete-stack --stack-name --region +``` diff --git a/DevOps/AWS/SAM/Local_AWS_development_with_SAM.md b/DevOps/AWS/SAM/Local_AWS_development_with_SAM.md new file mode 100644 index 0000000..18697a8 --- /dev/null +++ b/DevOps/AWS/SAM/Local_AWS_development_with_SAM.md @@ -0,0 +1,32 @@ +--- +categories: + - DevOps + - Backend +tags: [AWS, docker] +--- + +# Local AWS development with SAM + +We can run a local instance of our SAM stack for a given application without sending requests to the cloud. This is implemented through Docker. + +The SAM CLI handles all the Docker-related tasks, such as pulling the required Lambda runtime images, creating containers, mounting your code and dependencies, and running your Lambda functions inside those containers. + +## Basic set up + +Enter your project directory. + +First build your SAM application: + +```sh +sam build +``` + +We then run: + +```sh +sam local start-api +``` + +You should see the following: + +![](/_img/local-sam-docker.png) diff --git a/_img/cloud-formation-stack.png b/_img/cloud-formation-stack.png new file mode 100644 index 0000000..fc65b7a Binary files /dev/null and b/_img/cloud-formation-stack.png differ diff --git a/_img/gateway-trigger.png b/_img/gateway-trigger.png new file mode 100644 index 0000000..d43fe05 Binary files /dev/null and b/_img/gateway-trigger.png differ diff --git a/_img/local-sam-docker.png b/_img/local-sam-docker.png new file mode 100644 index 0000000..9f964fa Binary files /dev/null and b/_img/local-sam-docker.png differ diff --git a/_img/postman-aws-output.png b/_img/postman-aws-output.png new file mode 100644 index 0000000..7ce61fb Binary files /dev/null and b/_img/postman-aws-output.png differ