Skip to content

Simple example uses of different AWS services.

Notifications You must be signed in to change notification settings

tuomastik/aws-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

aws-examples

Simple example uses of different AWS services.

Cloud provisioning with infrastructure as code

  1. Install AWS Command Line Interface (CLI)

  2. Create SSH key pair for the EC2 instance

  3. Create/update/delete the CloudFormation stack:

    aws --region eu-north-1 cloudformation create-stack --stack-name ec2-only --template-body file://cloudformation/ec2.yaml
    aws --region eu-north-1 cloudformation update-stack --stack-name ec2-only --template-body file://cloudformation/ec2.yaml
    aws --region eu-north-1 cloudformation delete-stack --stack-name ec2-only
  4. Monitor the stack creation progress

CloudFormation extension optimized for serverless applications

  1. Install SAM CLI

    python -m pip install aws-sam-cli
  2. Build the AWS SAM application using sam build command.

    The sam build command processes your AWS SAM template file, application code, and any applicable language-specific files and dependencies, and copies build artifacts in the format and location expected by subsequent steps in your workflow.

    sam build \
        --template sam/lambda.yaml \
        --manifest sam/lambda-code/requirements.txt
  3. Run our serverless application locally for quick development and testing using Docker and sam local start-api command.

    Note: SAM CLI doesn't support schema validation like API Gateway does, so we have to deploy the SAM stack to check whether the validation is working.

    sam local start-api

    Send a testing request to the API:

    curl \
        --header "Content-Type: application/json" \
        --request POST \
        --data '{"searchTerm": "United States"}' \
        http://localhost:3000
  4. Package the AWS SAM application using sam package command.

    It creates a ZIP file of your code and dependencies, and uploads it to Amazon S3. It then returns a copy of your AWS SAM template, replacing references to local artifacts with the Amazon S3 location where the command uploaded the artifacts.

    Before running the following command, you need to create a S3 bucket for it.

    sam package \
        --s3-bucket my-cloudformation-templates-12345 \
        --output-template-file sam/lambda-packaged.yaml

    TODO: is this step needed anymore? https://stackoverflow.com/a/63061658/5524090

  5. Deploy the AWS SAM application using sam deploy command.

    sam deploy \
        --template sam/lambda-packaged.yaml \
        --stack-name my-first-sam-stack \
        --capabilities CAPABILITY_IAM \
        --region eu-north-1

Useful resources