Skip to content

Instantly share code, notes, and snippets.

View aquiseb's full-sized avatar

Sébastien aquiseb

View GitHub Profile
@aquiseb
aquiseb / 06.png
Created May 1, 2020 17:38 — forked from mfd/06.png
Gilroy font
06.png
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 60
Parameters:
Stage:
Type: String
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS API Gateway with a Lambda Integration
Parameters:
lambdaFunctionName:
Type: "String"
AllowedPattern: "^[a-zA-Z0-9]+[a-zA-Z0-9-]+[a-zA-Z0-9]+$"
Description: Lambda function name. (Recommend to keep default)
Default: "lambda-api"
@aquiseb
aquiseb / troubleshooting.md
Created April 18, 2020 23:20 — forked from cmawhorter/troubleshooting.md
Solution to AWS Lambda node.js UnrecognizedClientException "The security token included in the request is invalid."

Troubleshooting AWS unauthorized errors in lambda requests

This is mainly for node.js but might apply to other environments. Unsure.

If you are running a AWS Lambda function that calls another AWS service and getting an error about invalid tokens or other access denied errors, do this:

Check IAM

The role assigned to your lambda function will need permission to perform the actions. Check IAM and make sure the role has all the permissions.

Description: Web Application lambdas
Transform: AWS::Serverless-2016-10-31
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
Version:
Description: Version of this template
Type: String
EnvName:
Description: An environment name that is prefixed to resource names
Type: String
@aquiseb
aquiseb / README.md
Created April 18, 2020 19:10 — forked from magnetikonline/README.md
CloudFormation example for an API Gateway endpoint calling a Lambda function using proxy integration.

CloudFormation example for API Gateway integration to Lambda function

Template that will create the following:

  • API Gateway endpoint:
    • A single root method, accepting POST requests only with Lambda proxy integration to a function.
  • In-line Lambda function echoing back requesting users IP address to API Gateway requests:
    • IAM role for Lambda allowing CloudWatch logs access.
    • Permissions for Lambda that allow API Gateway endpoint to successfully invoke function.
  • CloudWatch logs group for Lambda, with 90 day log retention.

After standing up the template, you should be able to curl a POST request to the URL listed as the apiGatewayInvokeURL output value.

module.exports.handler = async (event) => {
console.log(JSON.stringify(event, 2));
return {
statusCode: 200,
body: "Echoing your message: " + event.echo
}
};
@aquiseb
aquiseb / MediumCFArticle8.yaml
Created April 18, 2020 13:44 — forked from serverlessunicorn/MediumCFArticle8.yaml
TWagnerMediumBlogSampleCFTemplatePart8
# The top-level websocket itself
NATPunchWebSocket:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: NATPunchWebSocket
ProtocolType: WEBSOCKET
RouteSelectionExpression: "$request.body.action"
# The builtin $connect path. This involves both a route
# definition and its integration definition, which follows, as well as a
@aquiseb
aquiseb / s3static.yaml
Created April 18, 2020 12:39 — forked from tehzwen/s3static.yaml
AWS cfn template for serverless
Resources:
ZachLambdaRole:
Type: AWS::IAM::Role
Properties:
Description: Lambda execution role for Zach
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
@aquiseb
aquiseb / crypto.go
Created February 15, 2020 19:24 — forked from miguelmota/crypto.go
Golang SHA256 hash example
package crypto
import (
"crypto/sha256"
)
// NewSHA256 ...
func NewSHA256(data []byte) []byte {
hash := sha256.Sum256(data)
return hash[:]