scenarios

package
v0.0.0-...-ba09527 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetStartedFunctionsScenario

type GetStartedFunctionsScenario struct {
	// contains filtered or unexported fields
}

GetStartedFunctionsScenario shows you how to use AWS Lambda to perform the following actions:

  1. Create an AWS Identity and Access Management (IAM) role and Lambda function, then upload handler code.
  2. Invoke the function with a single parameter and get results.
  3. Update the function code and configure with an environment variable.
  4. Invoke the function with new parameters and get results. Display the returned execution log.
  5. List the functions for your account, then clean up resources.

func NewGetStartedFunctionsScenario

func NewGetStartedFunctionsScenario(sdkConfig aws.Config, questioner demotools.IQuestioner,
	helper IScenarioHelper) GetStartedFunctionsScenario

NewGetStartedFunctionsScenario constructs a GetStartedFunctionsScenario instance from a configuration. It uses the specified config to get a Lambda client and create wrappers for the actions used in the scenario.

func (GetStartedFunctionsScenario) Cleanup

func (scenario GetStartedFunctionsScenario) Cleanup(role *iamtypes.Role, funcName string)

Cleanup removes the IAM and Lambda resources created by the example.

func (GetStartedFunctionsScenario) CreateFunction

func (scenario GetStartedFunctionsScenario) CreateFunction(role *iamtypes.Role) string

CreateFunction creates a Lambda function and uploads a handler written in Python. The code for the Python handler is packaged as a []byte in .zip format.

func (GetStartedFunctionsScenario) GetOrCreateRole

func (scenario GetStartedFunctionsScenario) GetOrCreateRole() *iamtypes.Role

GetOrCreateRole checks whether the specified role exists and returns it if it does. Otherwise, a role is created that specifies Lambda as a trusted principal. The AWSLambdaBasicExecutionRole managed policy is attached to the role and the role is returned.

func (GetStartedFunctionsScenario) InvokeCalculator

func (scenario GetStartedFunctionsScenario) InvokeCalculator(funcName string)

InvokeCalculator invokes the Lambda calculator function. The parameters are stored in a Go struct that is used to serialize the parameters to a JSON payload. That payload is then passed to the function. The result payload is deserialized to a Go struct that stores the result as either an int or float32, depending on the kind of operation that was specified.

func (GetStartedFunctionsScenario) InvokeIncrement

func (scenario GetStartedFunctionsScenario) InvokeIncrement(funcName string)

InvokeIncrement invokes a Lambda function that increments a number. The function parameters are contained in a Go struct that is used to serialize the parameters to a JSON payload that is passed to the function. The result payload is deserialized into a Go struct that contains an int value.

func (GetStartedFunctionsScenario) ListFunctions

func (scenario GetStartedFunctionsScenario) ListFunctions()

ListFunctions lists up to the specified number of functions for your account.

func (GetStartedFunctionsScenario) Run

func (scenario GetStartedFunctionsScenario) Run()

Run runs the interactive scenario.

func (GetStartedFunctionsScenario) UpdateFunction

func (scenario GetStartedFunctionsScenario) UpdateFunction(funcName string)

UpdateFunction updates the code for a Lambda function by uploading a simple arithmetic calculator written in Python. The code for the Python handler is packaged as a []byte in .zip format. After the code is updated, the configuration is also updated with a new log level that instructs the handler to log additional information.

type IScenarioHelper

type IScenarioHelper interface {
	Pause(secs int)
	CreateDeploymentPackage(sourceFile string, destinationFile string) *bytes.Buffer
}

IScenarioHelper abstracts I/O and wait functions from a scenario so that they can be mocked for unit testing.

type PolicyDocument

type PolicyDocument struct {
	Version   string
	Statement []PolicyStatement
}

PolicyDocument defines an AWS Identity and Access Management (IAM) policy document that can be serialized to JSON.

func (*PolicyDocument) String

func (doc *PolicyDocument) String() string

String serializes the policy document to a JSON string.

type PolicyStatement

type PolicyStatement struct {
	Effect    string
	Action    []string
	Principal map[string]string `json:",omitempty"`
	Resource  *string           `json:",omitempty"`
}

PolicyStatement defines a statement in a policy document.

type ScenarioHelper

type ScenarioHelper struct {
	HandlerPath string
}

ScenarioHelper lets the caller specify the path to Lambda handler functions.

func (*ScenarioHelper) CreateDeploymentPackage

func (helper *ScenarioHelper) CreateDeploymentPackage(sourceFile string, destinationFile string) *bytes.Buffer

CreateDeploymentPackage creates an AWS Lambda deployment package from a source file. The deployment package is stored in .zip format in a bytes.Buffer. The buffer can be used to pass a []byte to Lambda when creating the function. The specified destinationFile is the name to give the file when it's deployed to Lambda.

func (*ScenarioHelper) Pause

func (helper *ScenarioHelper) Pause(secs int)

Pause waits for the specified number of seconds.

Jump to

Keyboard shortcuts

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