glambda

package module
v0.0.0-...-ecc4d09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 19 Imported by: 1

README

GLambda Deployment Tool

GLambda is a simple deployment tool for AWS Lambda functions written in Go. It provides a way to create and update Lambda functions in the AWS ecosystem from the command line using a compact set of commands.

Prerequisites

To use GLambda, you will need an AWS account with appropriate permissions and an AWS CLI profile configured on your machine.

Installation

To install GLambda, run:

go install github.com/mr-joshcrane/glambda/cmd/glambda@latest

Usage

  1. Have AWS environment variables set up:
export AWS_ACCESS_KEY_ID=<your-access-key-id>
export AWS_SECRET_ACCESS_KEY=<your-secret-access-key>
export AWS_DEFAULT_REGION=<your-region>

You'll need IAM permissions, and lambda permissions. By default a single shared role is created for all lambdas. This will be extended in the future.

  1. Give the function you wish to deploy a name and a source file to package up and deploy.
glambda <lambdaName> <path/to/handler.go>

Replace <lambdaName> with the desired name for your Lambda function and <path/to/handler.go> with the path to your Lambda function's handler file.

The source file should have a main function that calls lambda.Start(handler). See https://pkg.go.dev/github.com/aws/aws-lambda-go/lambda#Start for more details.

Testing

GLambda comes with a set of unit tests to ensure its functionality. To run the tests, you can use the following command:

go test -v ./...

Contributing

Contributions to GLambda are welcome! If you encounter any bugs or have ideas for new features, feel free to submit an issue or create a pull request.

License

GLambda is open-source software licensed under the MIT License. See the LICENSE file for details.


Feel free to customize this README.md to include any additional information specific to your project.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultAssumeRolePolicy     = `` /* 130-byte string literal not displayed */
	AWSLambdaBasicExecutionRole = `arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole`
	ThisAWSAccountCondition     = `"Condition":{"StringEquals":{"aws:PrincipalAccount": "${aws:accountId}"}}"`
)

Functions

func Package

func Package(path string) ([]byte, error)

func Validate

func Validate(path string) error

Types

type Action

type Action interface {
	Do(c LambdaClient) error
}

func PrepareAction

func PrepareAction(c LambdaClient, name, path, roleARN string) (Action, error)

type CreateAction

type CreateAction struct {
	Name string
	Role string
	Pkg  []byte
}

func (CreateAction) Do

type ExecutionRole

type ExecutionRole struct {
	RoleName                 string
	AssumeRolePolicyDocument string
	ManagedPolicies          []string
	InLinePolicy             string
}

func (ExecutionRole) AttachInLinePolicyCommand

func (e ExecutionRole) AttachInLinePolicyCommand(policyName string) iam.PutRolePolicyInput

func (ExecutionRole) AttachManagedPolicyCommand

func (e ExecutionRole) AttachManagedPolicyCommand(policyARN string) iam.AttachRolePolicyInput

func (ExecutionRole) CreateRoleCommand

func (e ExecutionRole) CreateRoleCommand() iam.CreateRoleInput

type Lambda

type Lambda struct {
	Name           string
	HandlerPath    string
	ExecutionRole  ExecutionRole
	ResourcePolicy ResourcePolicy
}

func NewLambda

func NewLambda(name, handlerPath string, opts ...LambdaOptions) Lambda

func (Lambda) Deploy

func (l Lambda) Deploy() error

func (Lambda) PrepareExecutionRole

func (l Lambda) PrepareExecutionRole(cfg aws.Config) (string, error)

type LambdaClient

type LambdaClient interface {
	CreateFunction(ctx context.Context, params *lambda.CreateFunctionInput, optFns ...func(*lambda.Options)) (*lambda.CreateFunctionOutput, error)
	UpdateFunctionCode(ctx context.Context, params *lambda.UpdateFunctionCodeInput, optFns ...func(*lambda.Options)) (*lambda.UpdateFunctionCodeOutput, error)
	GetFunction(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error)
}

type LambdaOptions

type LambdaOptions func(l Lambda) Lambda

func WithExecutionRole

func WithExecutionRole(name string, opts ...RoleOptions) LambdaOptions

func WithResourcePolicy

func WithResourcePolicy(serviceName string) LambdaOptions

type ResourcePolicy

type ResourcePolicy struct {
	Sid       string
	Effect    string
	Principal string
	Action    string
	Resource  string
	Condition string
}

func (ResourcePolicy) CreateCommand

func (r ResourcePolicy) CreateCommand(lambdaName, accountID string) lambda.AddPermissionInput

type RoleOptions

type RoleOptions func(role *ExecutionRole)

func WithInlinePolicy

func WithInlinePolicy(policy string) RoleOptions

func WithManagedPolicies

func WithManagedPolicies(policyARNs ...string) RoleOptions

type UpdateAction

type UpdateAction struct {
	Name string
	Pkg  []byte
}

func (UpdateAction) Do

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL