Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/settle/settle.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const (
// longer than the other phases so a real CLI or SDK client can observe a
// running job and call TerminateJob on it before it finishes.
DefaultBatchJobRunDwell = 5 * time.Second

DefaultLambdaCreateSettle = 1 * time.Second // Lambda function State Pending->Active
DefaultLambdaUpdateSettle = 1 * time.Second // Lambda LastUpdateStatus InProgress->Successful
)

// Window is a read-time overlay describing a resource still settling into its
Expand Down
58 changes: 58 additions & 0 deletions providers/aws/lambda/account_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package lambda

import (
"context"

"github.com/stackshy/cloudemu/v2/services/serverless/driver"
)

// AWS Lambda default account limits, in bytes, from the Lambda quotas page
// (https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html):
// 300 GB of code storage for .zip functions and layers, a 50 MB zipped
// deployment package uploaded directly, and 250 MB unzipped including layers.
// The concurrency budget is accountConcurrentExecutionLimit.
const (
accountTotalCodeSizeLimit int64 = 300 * 1024 * 1024 * 1024
accountCodeSizeZipped int64 = 50 * 1024 * 1024
accountCodeSizeUnzipped int64 = 250 * 1024 * 1024
)

// GetAccountSettings reports the account's Lambda limits and current usage
// (GetAccountSettings). UnreservedConcurrentExecutions is the concurrency pool
// minus every function's reserved concurrency; FunctionCount counts functions,
// and the used TotalCodeSize sums the deployment packages of every function's
// $LATEST and published versions plus every layer version, since "each
// function version and layer version consumes storage". It is an AWS-only
// capability the Lambda server handler type-asserts for.
func (m *Mock) GetAccountSettings(_ context.Context) (*driver.AccountSettings, error) {
var (
functions int64
codeSize int64
)

all := m.funcs.All()
for name := range all {
functions++
codeSize += all[name].info.CodeSize

for _, v := range all[name].versions {
codeSize += v.codeSize
}
}

for _, ld := range m.layers.All() {
for _, lv := range ld.versions.All() {
codeSize += lv.ContentSize
}
}

return &driver.AccountSettings{
TotalCodeSizeLimit: accountTotalCodeSizeLimit,
CodeSizeUnzipped: accountCodeSizeUnzipped,
CodeSizeZipped: accountCodeSizeZipped,
ConcurrentExecutions: accountConcurrentExecutionLimit,
UnreservedConcurrentExecutions: accountConcurrentExecutionLimit - m.sumReservedConcurrencyExcept(""),
FunctionCount: functions,
TotalCodeSizeUsed: codeSize,
}, nil
}
23 changes: 12 additions & 11 deletions providers/aws/lambda/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

// CreateAlias creates a new alias pointing to a specific function version.
func (m *Mock) CreateAlias(_ context.Context, cfg driver.AliasConfig) (*driver.Alias, error) {
func (m *Mock) CreateAlias(ctx context.Context, cfg driver.AliasConfig) (*driver.Alias, error) {
m.mu.Lock()
defer m.mu.Unlock()

fd, ok := m.funcs.Get(cfg.FunctionName)
if !ok {
return nil, cerrors.Newf(cerrors.NotFound, "function %s not found", cfg.FunctionName)
return nil, m.errFunctionNotFound(ctx, cfg.FunctionName, "")
}

if fd.aliases.Has(cfg.Name) {
Expand Down Expand Up @@ -56,13 +56,13 @@ func (m *Mock) CreateAlias(_ context.Context, cfg driver.AliasConfig) (*driver.A
}

// UpdateAlias updates an existing alias configuration.
func (m *Mock) UpdateAlias(_ context.Context, cfg driver.AliasConfig) (*driver.Alias, error) {
func (m *Mock) UpdateAlias(ctx context.Context, cfg driver.AliasConfig) (*driver.Alias, error) {
m.mu.Lock()
defer m.mu.Unlock()

fd, ok := m.funcs.Get(cfg.FunctionName)
if !ok {
return nil, cerrors.Newf(cerrors.NotFound, "function %s not found", cfg.FunctionName)
return nil, m.errFunctionNotFound(ctx, cfg.FunctionName, "")
}

ad, ok := fd.aliases.Get(cfg.Name)
Expand Down Expand Up @@ -121,13 +121,13 @@ func (m *Mock) UpdateAlias(_ context.Context, cfg driver.AliasConfig) (*driver.A
// provisioned concurrency config and event invoke config. Real Lambda keeps
// these as sub-resources of the alias ARN, so a later alias with the same name
// starts with none of them instead of inheriting the old grants.
func (m *Mock) DeleteAlias(_ context.Context, functionName, aliasName string) error {
func (m *Mock) DeleteAlias(ctx context.Context, functionName, aliasName string) error {
m.mu.Lock()
defer m.mu.Unlock()

fd, ok := m.funcs.Get(functionName)
if !ok {
return cerrors.Newf(cerrors.NotFound, "function %s not found", functionName)
return m.errFunctionNotFound(ctx, functionName, "")
}

if !fd.aliases.Has(aliasName) {
Expand Down Expand Up @@ -166,15 +166,16 @@ func withoutKey[V any](src map[string]V, key string) map[string]V {
}

// GetAlias retrieves a specific alias for a function.
func (m *Mock) GetAlias(_ context.Context, functionName, aliasName string) (*driver.Alias, error) {
func (m *Mock) GetAlias(ctx context.Context, functionName, aliasName string) (*driver.Alias, error) {
fd, ok := m.funcs.Get(functionName)
if !ok {
return nil, cerrors.Newf(cerrors.NotFound, "function %s not found", functionName)
return nil, m.errFunctionNotFound(ctx, functionName, "")
}

ad, ok := fd.aliases.Get(aliasName)
if !ok {
return nil, cerrors.Newf(cerrors.NotFound, "alias %s not found", aliasName)
// Real Lambda's GetAlias text names the alias-qualified function ARN.
return nil, cerrors.Newf(cerrors.NotFound, "Cannot find alias arn: %s:%s", fd.info.ARN, aliasName)
}

ad.mu.Lock()
Expand All @@ -185,10 +186,10 @@ func (m *Mock) GetAlias(_ context.Context, functionName, aliasName string) (*dri
}

// ListAliases returns all aliases for a function.
func (m *Mock) ListAliases(_ context.Context, functionName string) ([]driver.Alias, error) {
func (m *Mock) ListAliases(ctx context.Context, functionName string) ([]driver.Alias, error) {
fd, ok := m.funcs.Get(functionName)
if !ok {
return nil, cerrors.Newf(cerrors.NotFound, "function %s not found", functionName)
return nil, m.errFunctionNotFound(ctx, functionName, "")
}

all := fd.aliases.All()
Expand Down
28 changes: 16 additions & 12 deletions providers/aws/lambda/awsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lambda
import (
"context"

cerrors "github.com/stackshy/cloudemu/v2/errors"
"github.com/stackshy/cloudemu/v2/services/serverless/driver"
)

Expand All @@ -16,13 +15,13 @@ import (
// surface.
//
//nolint:gocritic // hugeParam: interface method signature cannot be changed.
func (m *Mock) SetFunctionAWSConfig(_ context.Context, name string, cfg driver.AWSFunctionConfig, create bool) error {
func (m *Mock) SetFunctionAWSConfig(ctx context.Context, name string, cfg driver.AWSFunctionConfig, create bool) error {
m.mu.Lock()
defer m.mu.Unlock()

fd, ok := m.funcs.Get(name)
if !ok {
return cerrors.Newf(cerrors.NotFound, "function %s not found", name)
return m.errFunctionNotFound(ctx, name, "")
}

if create {
Expand Down Expand Up @@ -78,18 +77,23 @@ func overlayAWSConfig(dst *driver.AWSFunctionConfig, cfg driver.AWSFunctionConfi

// GetFunctionAWSConfig returns a copy of the stored AWS-only settings for a
// function.
func (m *Mock) GetFunctionAWSConfig(_ context.Context, name string) (driver.AWSFunctionConfig, error) {
func (m *Mock) GetFunctionAWSConfig(ctx context.Context, name string) (driver.AWSFunctionConfig, error) {
fd, ok := m.funcs.Get(name)
if !ok {
return driver.AWSFunctionConfig{}, cerrors.Newf(cerrors.NotFound, "function %s not found", name)
return driver.AWSFunctionConfig{}, m.errFunctionNotFound(ctx, name, "")
}

return cloneAWSConfig(&fd.awsConfig), nil
}

// cloneAWSConfig deep-copies a function's AWS-only settings.
func cloneAWSConfig(c *driver.AWSFunctionConfig) driver.AWSFunctionConfig {
return driver.AWSFunctionConfig{
VPCConfig: cloneVPCConfig(fd.awsConfig.VPCConfig),
DeadLetterConfig: cloneDeadLetterConfig(fd.awsConfig.DeadLetterConfig),
TracingConfig: cloneTracingConfig(fd.awsConfig.TracingConfig),
Architectures: cloneArchitectures(fd.awsConfig.Architectures),
EphemeralStorage: cloneEphemeralStorage(fd.awsConfig.EphemeralStorage),
Layers: cloneLayers(fd.awsConfig.Layers),
}, nil
VPCConfig: cloneVPCConfig(c.VPCConfig),
DeadLetterConfig: cloneDeadLetterConfig(c.DeadLetterConfig),
TracingConfig: cloneTracingConfig(c.TracingConfig),
Architectures: cloneArchitectures(c.Architectures),
EphemeralStorage: cloneEphemeralStorage(c.EphemeralStorage),
Layers: cloneLayers(c.Layers),
}
}
Loading
Loading