mirror of
https://github.com/Luzifer/share.git
synced 2024-12-21 02:51:17 +00:00
890 lines
28 KiB
Go
890 lines
28 KiB
Go
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
|
|
|
|
package lambda_test
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
"github.com/aws/aws-sdk-go/service/lambda"
|
|
)
|
|
|
|
var _ time.Duration
|
|
var _ strings.Reader
|
|
var _ aws.Config
|
|
|
|
func parseTime(layout, value string) *time.Time {
|
|
t, err := time.Parse(layout, value)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &t
|
|
}
|
|
|
|
// add-permission
|
|
//
|
|
// This example adds a permission for an S3 bucket to invoke a Lambda function.
|
|
func ExampleLambda_AddPermission_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.AddPermissionInput{
|
|
Action: aws.String("lambda:InvokeFunction"),
|
|
FunctionName: aws.String("MyFunction"),
|
|
Principal: aws.String("s3.amazonaws.com"),
|
|
SourceAccount: aws.String("123456789012"),
|
|
SourceArn: aws.String("arn:aws:s3:::examplebucket/*"),
|
|
StatementId: aws.String("ID-1"),
|
|
}
|
|
|
|
result, err := svc.AddPermission(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeResourceConflictException:
|
|
fmt.Println(lambda.ErrCodeResourceConflictException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodePolicyLengthExceededException:
|
|
fmt.Println(lambda.ErrCodePolicyLengthExceededException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// create-function
|
|
//
|
|
// This example creates a Lambda function.
|
|
func ExampleLambda_CreateFunction_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.CreateFunctionInput{
|
|
Code: &lambda.FunctionCode{},
|
|
Description: aws.String(""),
|
|
FunctionName: aws.String("MyFunction"),
|
|
Handler: aws.String("souce_file.handler_name"),
|
|
MemorySize: aws.Int64(128),
|
|
Publish: aws.Bool(true),
|
|
Role: aws.String("arn:aws:iam::123456789012:role/service-role/role-name"),
|
|
Runtime: aws.String("nodejs4.3"),
|
|
Timeout: aws.Int64(15),
|
|
VpcConfig: &lambda.VpcConfig{},
|
|
}
|
|
|
|
result, err := svc.CreateFunction(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeResourceConflictException:
|
|
fmt.Println(lambda.ErrCodeResourceConflictException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeCodeStorageExceededException:
|
|
fmt.Println(lambda.ErrCodeCodeStorageExceededException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To delete a Lambda function alias
|
|
//
|
|
// This operation deletes a Lambda function alias
|
|
func ExampleLambda_DeleteAlias_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.DeleteAliasInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Name: aws.String("alias"),
|
|
}
|
|
|
|
result, err := svc.DeleteAlias(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To delete a Lambda function event source mapping
|
|
//
|
|
// This operation deletes a Lambda function event source mapping
|
|
func ExampleLambda_DeleteEventSourceMapping_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.DeleteEventSourceMappingInput{
|
|
UUID: aws.String("12345kxodurf3443"),
|
|
}
|
|
|
|
result, err := svc.DeleteEventSourceMapping(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To delete a Lambda function
|
|
//
|
|
// This operation deletes a Lambda function
|
|
func ExampleLambda_DeleteFunction_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.DeleteFunctionInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Qualifier: aws.String("1"),
|
|
}
|
|
|
|
result, err := svc.DeleteFunction(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeResourceConflictException:
|
|
fmt.Println(lambda.ErrCodeResourceConflictException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieves a Lambda customer's account settings
|
|
//
|
|
// This operation retrieves a Lambda customer's account settings
|
|
func ExampleLambda_GetAccountSettings_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.GetAccountSettingsInput{}
|
|
|
|
result, err := svc.GetAccountSettings(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a Lambda function alias
|
|
//
|
|
// This operation retrieves a Lambda function alias
|
|
func ExampleLambda_GetAlias_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.GetAliasInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Name: aws.String("myFunctionAlias"),
|
|
}
|
|
|
|
result, err := svc.GetAlias(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a Lambda function's event source mapping
|
|
//
|
|
// This operation retrieves a Lambda function's event source mapping
|
|
func ExampleLambda_GetEventSourceMapping_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.GetEventSourceMappingInput{
|
|
UUID: aws.String("123489-xxxxx-kdla8d89d7"),
|
|
}
|
|
|
|
result, err := svc.GetEventSourceMapping(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a Lambda function's event source mapping
|
|
//
|
|
// This operation retrieves a Lambda function's event source mapping
|
|
func ExampleLambda_GetFunction_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.GetFunctionInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Qualifier: aws.String("1"),
|
|
}
|
|
|
|
result, err := svc.GetFunction(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a Lambda function's event source mapping
|
|
//
|
|
// This operation retrieves a Lambda function's event source mapping
|
|
func ExampleLambda_GetFunctionConfiguration_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.GetFunctionConfigurationInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Qualifier: aws.String("1"),
|
|
}
|
|
|
|
result, err := svc.GetFunctionConfiguration(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a Lambda function policy
|
|
//
|
|
// This operation retrieves a Lambda function policy
|
|
func ExampleLambda_GetPolicy_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.GetPolicyInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Qualifier: aws.String("1"),
|
|
}
|
|
|
|
result, err := svc.GetPolicy(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To invoke a Lambda function
|
|
//
|
|
// This operation invokes a Lambda function
|
|
func ExampleLambda_Invoke_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.InvokeInput{
|
|
ClientContext: aws.String("MyApp"),
|
|
FunctionName: aws.String("MyFunction"),
|
|
InvocationType: aws.String("Event"),
|
|
LogType: aws.String("Tail"),
|
|
Payload: []byte("fileb://file-path/input.json"),
|
|
Qualifier: aws.String("1"),
|
|
}
|
|
|
|
result, err := svc.Invoke(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidRequestContentException:
|
|
fmt.Println(lambda.ErrCodeInvalidRequestContentException, aerr.Error())
|
|
case lambda.ErrCodeRequestTooLargeException:
|
|
fmt.Println(lambda.ErrCodeRequestTooLargeException, aerr.Error())
|
|
case lambda.ErrCodeUnsupportedMediaTypeException:
|
|
fmt.Println(lambda.ErrCodeUnsupportedMediaTypeException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeEC2UnexpectedException:
|
|
fmt.Println(lambda.ErrCodeEC2UnexpectedException, aerr.Error())
|
|
case lambda.ErrCodeSubnetIPAddressLimitReachedException:
|
|
fmt.Println(lambda.ErrCodeSubnetIPAddressLimitReachedException, aerr.Error())
|
|
case lambda.ErrCodeENILimitReachedException:
|
|
fmt.Println(lambda.ErrCodeENILimitReachedException, aerr.Error())
|
|
case lambda.ErrCodeEC2ThrottledException:
|
|
fmt.Println(lambda.ErrCodeEC2ThrottledException, aerr.Error())
|
|
case lambda.ErrCodeEC2AccessDeniedException:
|
|
fmt.Println(lambda.ErrCodeEC2AccessDeniedException, aerr.Error())
|
|
case lambda.ErrCodeInvalidSubnetIDException:
|
|
fmt.Println(lambda.ErrCodeInvalidSubnetIDException, aerr.Error())
|
|
case lambda.ErrCodeInvalidSecurityGroupIDException:
|
|
fmt.Println(lambda.ErrCodeInvalidSecurityGroupIDException, aerr.Error())
|
|
case lambda.ErrCodeInvalidZipFileException:
|
|
fmt.Println(lambda.ErrCodeInvalidZipFileException, aerr.Error())
|
|
case lambda.ErrCodeKMSDisabledException:
|
|
fmt.Println(lambda.ErrCodeKMSDisabledException, aerr.Error())
|
|
case lambda.ErrCodeKMSInvalidStateException:
|
|
fmt.Println(lambda.ErrCodeKMSInvalidStateException, aerr.Error())
|
|
case lambda.ErrCodeKMSAccessDeniedException:
|
|
fmt.Println(lambda.ErrCodeKMSAccessDeniedException, aerr.Error())
|
|
case lambda.ErrCodeKMSNotFoundException:
|
|
fmt.Println(lambda.ErrCodeKMSNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidRuntimeException:
|
|
fmt.Println(lambda.ErrCodeInvalidRuntimeException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To invoke a Lambda function asynchronously
|
|
//
|
|
// This operation invokes a Lambda function asynchronously
|
|
func ExampleLambda_InvokeAsync_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.InvokeAsyncInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
InvokeArgs: aws.ReadSeekCloser(strings.NewReader("fileb://file-path/input.json")),
|
|
}
|
|
|
|
result, err := svc.InvokeAsync(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidRequestContentException:
|
|
fmt.Println(lambda.ErrCodeInvalidRequestContentException, aerr.Error())
|
|
case lambda.ErrCodeInvalidRuntimeException:
|
|
fmt.Println(lambda.ErrCodeInvalidRuntimeException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a Lambda function aliases
|
|
//
|
|
// This operation retrieves a Lambda function's aliases
|
|
func ExampleLambda_ListAliases_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.ListAliasesInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
FunctionVersion: aws.String("1"),
|
|
Marker: aws.String(""),
|
|
MaxItems: aws.Int64(123),
|
|
}
|
|
|
|
result, err := svc.ListAliases(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a list of Lambda functions
|
|
//
|
|
// This operation retrieves a Lambda functions
|
|
func ExampleLambda_ListFunctions_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.ListFunctionsInput{
|
|
Marker: aws.String(""),
|
|
MaxItems: aws.Int64(123),
|
|
}
|
|
|
|
result, err := svc.ListFunctions(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To retrieve a list of Lambda function versions
|
|
//
|
|
// This operation retrieves a Lambda function versions
|
|
func ExampleLambda_ListVersionsByFunction_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.ListVersionsByFunctionInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Marker: aws.String(""),
|
|
MaxItems: aws.Int64(123),
|
|
}
|
|
|
|
result, err := svc.ListVersionsByFunction(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To publish a version of a Lambda function
|
|
//
|
|
// This operation publishes a version of a Lambda function
|
|
func ExampleLambda_PublishVersion_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.PublishVersionInput{
|
|
CodeSha256: aws.String(""),
|
|
Description: aws.String(""),
|
|
FunctionName: aws.String("myFunction"),
|
|
}
|
|
|
|
result, err := svc.PublishVersion(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeCodeStorageExceededException:
|
|
fmt.Println(lambda.ErrCodeCodeStorageExceededException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To remove a Lambda function's permissions
|
|
//
|
|
// This operation removes a Lambda function's permissions
|
|
func ExampleLambda_RemovePermission_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.RemovePermissionInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Qualifier: aws.String("1"),
|
|
StatementId: aws.String("role-statement-id"),
|
|
}
|
|
|
|
result, err := svc.RemovePermission(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To update a Lambda function alias
|
|
//
|
|
// This operation updates a Lambda function alias
|
|
func ExampleLambda_UpdateAlias_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.UpdateAliasInput{
|
|
Description: aws.String(""),
|
|
FunctionName: aws.String("myFunction"),
|
|
FunctionVersion: aws.String("1"),
|
|
Name: aws.String("functionAlias"),
|
|
}
|
|
|
|
result, err := svc.UpdateAlias(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To update a Lambda function event source mapping
|
|
//
|
|
// This operation updates a Lambda function event source mapping
|
|
func ExampleLambda_UpdateEventSourceMapping_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.UpdateEventSourceMappingInput{
|
|
BatchSize: aws.Int64(123),
|
|
Enabled: aws.Bool(true),
|
|
FunctionName: aws.String("myFunction"),
|
|
UUID: aws.String("1234xCy789012"),
|
|
}
|
|
|
|
result, err := svc.UpdateEventSourceMapping(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeResourceConflictException:
|
|
fmt.Println(lambda.ErrCodeResourceConflictException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To update a Lambda function's code
|
|
//
|
|
// This operation updates a Lambda function's code
|
|
func ExampleLambda_UpdateFunctionCode_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.UpdateFunctionCodeInput{
|
|
FunctionName: aws.String("myFunction"),
|
|
Publish: aws.Bool(true),
|
|
S3Bucket: aws.String("myBucket"),
|
|
S3Key: aws.String("myKey"),
|
|
S3ObjectVersion: aws.String("1"),
|
|
ZipFile: []byte("fileb://file-path/file.zip"),
|
|
}
|
|
|
|
result, err := svc.UpdateFunctionCode(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeCodeStorageExceededException:
|
|
fmt.Println(lambda.ErrCodeCodeStorageExceededException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|
|
|
|
// To update a Lambda function's configuration
|
|
//
|
|
// This operation updates a Lambda function's configuration
|
|
func ExampleLambda_UpdateFunctionConfiguration_shared00() {
|
|
svc := lambda.New(session.New())
|
|
input := &lambda.UpdateFunctionConfigurationInput{
|
|
Description: aws.String(""),
|
|
FunctionName: aws.String("myFunction"),
|
|
Handler: aws.String("index.handler"),
|
|
MemorySize: aws.Int64(128),
|
|
Role: aws.String("arn:aws:iam::123456789012:role/lambda_basic_execution"),
|
|
Runtime: aws.String("python2.7"),
|
|
Timeout: aws.Int64(123),
|
|
VpcConfig: &lambda.VpcConfig{},
|
|
}
|
|
|
|
result, err := svc.UpdateFunctionConfiguration(input)
|
|
if err != nil {
|
|
if aerr, ok := err.(awserr.Error); ok {
|
|
switch aerr.Code() {
|
|
case lambda.ErrCodeServiceException:
|
|
fmt.Println(lambda.ErrCodeServiceException, aerr.Error())
|
|
case lambda.ErrCodeResourceNotFoundException:
|
|
fmt.Println(lambda.ErrCodeResourceNotFoundException, aerr.Error())
|
|
case lambda.ErrCodeInvalidParameterValueException:
|
|
fmt.Println(lambda.ErrCodeInvalidParameterValueException, aerr.Error())
|
|
case lambda.ErrCodeTooManyRequestsException:
|
|
fmt.Println(lambda.ErrCodeTooManyRequestsException, aerr.Error())
|
|
case lambda.ErrCodeResourceConflictException:
|
|
fmt.Println(lambda.ErrCodeResourceConflictException, aerr.Error())
|
|
default:
|
|
fmt.Println(aerr.Error())
|
|
}
|
|
} else {
|
|
// Print the error, cast err to awserr.Error to get the Code and
|
|
// Message from an error.
|
|
fmt.Println(err.Error())
|
|
}
|
|
return
|
|
}
|
|
|
|
fmt.Println(result)
|
|
}
|