Git Product home page Git Product logo

aws-samples / sessions-with-aws-sam Goto Github PK

View Code? Open in Web Editor NEW
377.0 16.0 101.0 992 KB

This repo contains all the SAM templates created in the Twitch series #SessionsWithSAM. The show is every Thursday on Twitch at 10 AM PDT.

Home Page: https://slip.link/sws-vids

License: MIT No Attribution

JavaScript 65.14% C# 1.15% Dockerfile 0.35% Makefile 1.13% Swift 2.12% Go 2.00% TypeScript 10.20% HTML 1.30% Vue 12.42% CSS 0.04% Python 4.15%
sam serverless aws

sessions-with-aws-sam's Introduction

Sessions With SAM

This repo contains all the SAM templates created in the Twitch series #SessionsWithSAM. The show is every Thursday on Twitch at 10 AM PDT.

Episodes

Simple HTTP API with JWT Authorizer

In this episode I build a SAM template for HTTP API with a non-authenticated route and an authenticated route.

Code | Video

Cognito and HTTP API

In this episode I talk through building an Amazon Cognito identity provider for HTTP API and JWT authorization. I also talk through using Cognito user groups as custom scopes for route access.

Code | Video

EventBridge

In this session we build a custom EventBridge bus and an HTTP API endpoint to push data into it. We also add multiple rules to trigger Lambda functions for asynchronous processing.

Code | Video

Building a Kinesis Firehose application for ingesting website access logs

In this session we build an Amazon Kinesis Firehose SAM template for ingesting website access logs from Amazon API Gateway. The data is stored in a raw bucket, processed by a Lambda function, and then stored in a processed bucket as well. During the processing period, the data is also pushed to an Amazon DynamoDB table for real-time analytics.

Code | Video

Analyzing API Gateway access logs using Kinesis

Continuing from session 4, this session adds a Kinesis Data Analytics application to create real-time analytics from API Gateway access logs. The entire application is built using SAM templates and the SAM CLI.

Code | Video

SAM templates for SQS, cross-account queue policies & Lambda event sources

In this session with SAM we build an AWS SAM template for creating an Amazon SQS queue. We also connect the queue as an event source for a Lambda function. Finally we create a queue policy to allow cross account posting to the queue and show how to test it in Postman.

Code | Video

Creating safe linear and canary deploys for Lambda functions

In this session I show how to use SAM to create safe deployments for Lambda functions in serverless applications. I demonstrate linear and canary deployments and how to configure pre and post traffic tests.

Code | Video

SAM templates for HTTP API and REST API custom domains

In this session I create a SAM template that builds a custom domain for API Gateway HTTP APIs and REST APIs. The template generates the hosted zone and ssl cert as well. I also show how to attach the same custom domain to both HTTP API and REST API at the same time.

Code | Video

Managing AWS Step Functions as IaC with SAM

In this episode I am joined by AWS Serverless DA Rob Sutter. Together we talk through the new Step Functions state machine support in AWS SAM.

Code | Video

Creating a Lambda function with an Amazon EFS mounted using SAM

In this episode James Beswick and I talk through configuring Amazon EFS for Lambda functions. This includes configuring EFS in a VOC as well. All by using SAM and SAM CLI.

Code | Video

Using SAM and Stackery to build .Net Lambda functions

In this episode, I am joined by Chase Douglas, Stackery CTO. We talk through using SAM with Stackery to manage .NET Serverless applications.

Code | Video

Using SAM to create and use secrets

In this session we cover using AWS Systems Manager Parameter Store and the AWS Secrets Manager within AWS SAM templates. Using these services helps developers store account specific secrets that are easily utilized by SAM on application creation and updates.

Code | Video

Adding governance to serverless applications with AWS Config and AWS SAM

This session is the first of four on adding governance to serverless application. In this session I demonstrate configuring an account to record and store governance data in AWS Config with AWS SAM.

Code | Video

Using the new HTTP APIs direct integrations in AWS SAM

In this session I will walk through creating a direct service integration on HTTP API. We will cover building it in the console and exporting for use with AWS SAM.

Code | Video

Adding governance to serverless applications with AWS Config and AWS SAM Part 2

This session is the second of four on adding governance to serverless application. In this session I demonstrate configuring AWS managed rules used in AWS Config.

Code | Video

Adding governance to serverless applications with AWS Config and AWS SAM Part 3

This session is the third of four on adding governance to serverless application. In this session I demonstrate building custom rules for AWS Config.

Code | Video

Adding governance to serverless applications with AWS Config and AWS SAM Part 4

This session is the final of four on adding governance to serverless application. In this session I demonstrate making the initial setup template reusable across regions and accounts. I also add aggregates to collect data from multiple accounts on a single dashboard..

Code | Video

Using SAM CLI custom build

This session covers using the AWSSAM CLI custom build to use Makefiles in the build process. THis example demonstrates using webpack in node apps. Code | Video

Lambda Layers

This session talks through using Lambda layers externally and internal to the application. It also covers local development with Layers. Code | Video

Additional Templates

These templates do not have an accompanying episode or it has not aired yet.

HTTP API Access logging

This template shows how to setup access logging on an HTTP API gateay. Code

Building custom runtime - Swift example

This projects builds two Lambda functions built with Swift. Squared is a simple Lambda that returns the squared value of a number. SwiftApi is a simple Lambda function that triggers from an HTTP API. Code

Running Go as a custom runtime on Amazon Linux 2

This project demonstrates running Go on al2 with the new provided.al2 custom runtime. Code

HTTP APIs service integration blog example

This template builds an HTTP APIs service integration to SQS with a Lambda function for testing. Code | Blog

API Gateway enhanced observability variables

This example demonstrates using the new API Gateway enhanced observability variables to get the full story of an API Gateway request and response. Code

EventBridge DLQ and retry policy config

This template creates an HTTP API with a direct integration to the EventBridge default bus. It also creates an EventBridge rule with a Lambda function as a trigger. The template also configures a DLQ and a retry policy for the EventBridge rule. Code

Using AWS AppConfig with AWS Lambda Extensions - Gunnar Grosch

This is an example of how AWS AppConfig can be used with AWS Lambda and Lambda Extensions. Using AppConfig to separate your application configuration from your application code is good practice. By using that, you are able to deploy configuration changes independently from your code. AWS AppConfig helps us achieve that.This example will deploy a sample serverless applications with AWS AppConfig and the AppConfig Lambda layer needed for AWS Lambda Extensions using AWS SAM. Code


See the full YouTube playlist https://slip.link/sws-vids

sessions-with-aws-sam's People

Contributors

amazon-auto avatar dependabot[bot] avatar drobbins-ancile avatar excircle avatar gunnargrosch avatar guysqr avatar jbesw avatar leopic avatar pcolazurdo avatar rts-rob avatar singledigit avatar txase avatar weisisheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sessions-with-aws-sam's Issues

Unable to deploy Swift samples

Seems to be related to the Output block of the template, but after running sam deploy I ran into this error:

โžœ  swift-custom-runtime git:(master) sam deploy

	Deploying with following values
	===============================
	Stack name                 : swift-lambda-test
	Region                     : us-east-1
	Confirm changeset          : False
	Deployment s3 bucket       : aws-sam-cli-managed-default-samclisourcebucket-10u0ftc8l2tv
	Capabilities               : ["CAPABILITY_IAM"]
	Parameter overrides        : {}

Initiating deployment
=====================
SwiftApi may not have authorization defined.

Waiting for changeset to be created..
Error: Failed to create changeset for the stack: swift-lambda-test, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Unresolved resource dependencies [ServerlessHttpApi] in the Outputs block of the template

Using

  • Docker version 19.03.8, build afacb8b
  • SAM CLI, version 0.53.0
  • macOS Catalina 10.15.5

Swift Custom Runtime: CodeBuild S3 caching not working

Hey ๐Ÿ‘‹, So I would like to create a pipeline that compiles my swift lambda and deploys via sam.
So far it works great. Codebuild builds the swift lambdas in my project and packages it via sam package.

Unfortunately the Codebuild S3 Cache does not work with swift build. Currently my build times are around the 10 min mark. So a cache would bring that down and save cost.
Currently my setup looks like the following:

Slightly modified makefile as we do not need to execute docker here:

build-SomeTestFunction: builder-bot

builder-bot:
	$(eval $@PRODUCT = $(subst build-,,$(MAKECMDGOALS)))
	$(eval $@BUILD_DIR = $(PWD)/.aws-sam/build-$($@PRODUCT))
	$(eval $@STAGE = $($@BUILD_DIR)/lambda)
	$(eval $@ARTIFACTS_DIR = $(PWD)/.aws-sam/build/$($@PRODUCT))

	# prep directories
	mkdir -p $($@BUILD_DIR)/lambda $($@ARTIFACTS_DIR)

	# Compile application
	swift build --product $($@PRODUCT) -c release --build-path $($@BUILD_DIR)

	# copy deps
	ldd '/$($@BUILD_DIR)/release/$($@PRODUCT)' | grep swift | cut -d' ' -f3 | xargs cp -Lv -t /$($@BUILD_DIR)/lambda

	# copy binary to stage
	cp $($@BUILD_DIR)/release/$($@PRODUCT) $($@BUILD_DIR)/lambda/bootstrap

	# copy app from stage to artifacts dir
	cp $($@STAGE)/* $($@ARTIFACTS_DIR)

Buildspec.yml

version: 0.2
phases:
  pre_build:
    commands:
      - mkdir -p /build-directory
      - cp -a ${CODEBUILD_SRC_DIR}/. /build-directory
      - cd /build-directory
  build:
    commands:
      - cd /build-directory
      - sam build
      - sam package -t template.yml --s3-bucket {bucketName} --output-template-file packaged.yaml

  post_build:
    commands:
      - cd /build-directory
      - cp -a /build-directory/. ${CODEBUILD_SRC_DIR}

artifacts:
  files:
    - packaged.yaml
cache:
  paths:
    - ".aws-sam/**/*"

Because sam build does not use relative paths and each codebuild could be on different machines so the paths are different each time. After some digging i found this post over on stack overflow that I should copy the ${CODEBUILD_SRC_DIR} into a temp directory. And indeed that works. I do not get any errors anymore and the compile succeeds but unfortunately no caching.

Now to the question. Did you get codepipline including caching to work for swift custom runtime ? If so what did you do or what did I do wrong.

I would really appreciate your help.
Thanks!

Unable to invoke Swift examples

Thank you for putting this repo together, I'm an iOS Developer that had my eye on working with the custom Swift runtime when it became available.

On to the issue, I am unable to run either of the lambdas, this the error for both of them:

โžœ  swift-custom-runtime git:(master) sam local invoke Squared -e events/sqaured-event.json
Invoking swift.bootstrap (provided)

Fetching lambci/lambda:provided Docker container image......
Mounting /Users/leo/Sites/aws-swift-lambda/sessions-with-aws-sam/swift-custom-runtime as /var/task:ro,delegated inside runtime container
START RequestId: 7e406ac6-09c0-1fcb-d682-753a6fe75e28 Version: $LATEST
END RequestId: 7e406ac6-09c0-1fcb-d682-753a6fe75e28
REPORT RequestId: 7e406ac6-09c0-1fcb-d682-753a6fe75e28	Init Duration: 24.25 ms	Duration: 1.34 ms	Billed Duration: 100 ms	Memory Size: 512 MB	Max Memory Used: 7 MB

{"errorType":"exitError","errorMessage":"RequestId: 7e406ac6-09c0-1fcb-d682-753a6fe75e28 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}

---

โžœ  swift-custom-runtime git:(master) sam local invoke SwiftApi -e events/api-event.json
Invoking swift.bootstrap (provided)

Fetching lambci/lambda:provided Docker container image......
Mounting /Users/leo/Sites/aws-swift-lambda/sessions-with-aws-sam/swift-custom-runtime as /var/task:ro,delegated inside runtime container
START RequestId: 1d33feac-9719-10a0-a269-bdc6a1094ce9 Version: $LATEST
END RequestId: 1d33feac-9719-10a0-a269-bdc6a1094ce9
REPORT RequestId: 1d33feac-9719-10a0-a269-bdc6a1094ce9	Init Duration: 20.96 ms	Duration: 0.74 ms	Billed Duration: 100 ms	Memory Size: 512 MB	Max Memory Used: 7 MB

{"errorType":"exitError","errorMessage":"RequestId: 1d33feac-9719-10a0-a269-bdc6a1094ce9 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}

Using:

  • Docker version 19.03.8, build afacb8b
  • SAM CLI, version 0.53.0
  • macOS Catalina 10.15.5

FWIW: the Squared example also fails to run in AWS with a similar error:

START RequestId: 83e1552b-8157-42e3-a57c-b0d4184bed91 Version: $LATEST
END RequestId: 83e1552b-8157-42e3-a57c-b0d4184bed91
REPORT RequestId: 83e1552b-8157-42e3-a57c-b0d4184bed91	Duration: 26.78 ms	Billed Duration: 100 ms	Memory Size: 512 MB	Max Memory Used: 5 MB	
RequestId: 83e1552b-8157-42e3-a57c-b0d4184bed91 Error: &{0xc0000cc070 map[error:Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap] invoke_id:83e1552b-8157-42e3-a57c-b0d4184bed91 sandbox_id:0] 2020-07-19 21:47:23.284976935 +0000 UTC m=+0.007731215 panic <nil> Failed to locate runtime bootstrap <nil> <nil> }
Runtime.ExitError

On Lambda-Layers example, getting message forbidden error...

Hitting the endpoint on postman with Get and #403 error surfaces.

Tried with the principal referencing the AccountId per the example and also replaced with Principal: '*'. Neither fixed the issue.

Welcome any trialheads or tips as I am stumped given there are no other authentication features to this.

Couldn't get the example "provided.al2" for GoLang working

Description

I tried to check out the go-al2 example at https://github.com/aws-samples/sessions-with-aws-sam/tree/master/go-al2
But it failed when running sam build

$ sam build --debug
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
'build' command is called
No Parameters detected in the template
1 resources found in the template
Found Serverless function with name='HelloWorldFunction' and CodeUri='hello-world/'
No Parameters detected in the template
Building function 'HelloWorldFunction'
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'GoDepBuilder' with capability 'Capability(language='go', dependency_manager='dep', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Running workflow 'CustomMakeBuilder'
Running CustomMakeBuilder:CopySource
CustomMakeBuilder:CopySource succeeded
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /Users/phampp/go/src/go-al2/.aws-sam/build/HelloWorldFunction
executing Make: ['make', '--makefile', '/Users/phampp/go/src/go-al2/hello-world/Makefile', 'build-HelloWorldFunction']
CustomMakeBuilder:MakeBuild failed
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/1.1.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 94, in execute
    cwd=self.scratch_dir,
  File "/usr/local/Cellar/aws-sam-cli/1.1.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/make.py", line 88, in run
    raise MakeExecutionError(message=err.decode("utf8").strip())
aws_lambda_builders.workflows.custom_make.make.MakeExecutionError: Make Failed: cp: hello-world: No such file or directory
make: *** [build-HelloWorldFunction] Error 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/1.1.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/Cellar/aws-sam-cli/1.1.0/libexec/lib/python3.7/site-packages/aws_lambda_builders/workflows/custom_make/actions.py", line 97, in execute
    raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Make Failed: cp: hello-world: No such file or directory
make: *** [build-HelloWorldFunction] Error 1

Build Failed
Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'duration': 4395, 'exitReason': 'WorkflowFailedError', 'exitCode': 1, 'requestId': '62b345ee-610b-4ffa-b679-7331056509a7', 'installationId': '1355e8b0-9682-46b1-a8c8-8681022f2b0b', 'sessionId': 'a884f460-c2c9-471f-96f1-2613661bfc85', 'executionEnvironment': 'CLI', 'pyversion': '3.7.8', 'samcliVersion': '1.1.0'}}]}
HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: CustomMakeBuilder:MakeBuild - Make Failed: cp: hello-world: No such file or directory
make: *** [build-HelloWorldFunction] Error 1

SAM Version: SAM CLI, version 1.1.0
Mac OS 10.14.6

Last few lines of template are extraneous?

Fairly new to SAM but the example template for Eventbridge won't deploy for me unless I comment out these lines. Originally I thought it was the missing quote on the Description line.

MyNotificationArn:
Description: Topic ARN"
Value: !Ref AWS::NotificationARNs

I don't see them referenced elsewhere and they're not in the instructional video.

Please advise. Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.