Support for DeadLetterConfig on aws.lambda.Function resources
This commit is contained in:
parent
837d13d393
commit
f45e80e28d
2 changed files with 59 additions and 25 deletions
|
@ -77,7 +77,6 @@ func (p *funcProvider) Check(ctx context.Context, obj *lambda.Function, property
|
|||
// Create allocates a new instance of the provided resource and returns its unique ID afterwards. (The input ID
|
||||
// must be blank.) If this call fails, the resource must not have been created (i.e., it is "transacational").
|
||||
func (p *funcProvider) Create(ctx context.Context, obj *lambda.Function) (resource.ID, error) {
|
||||
contract.Assertf(obj.DeadLetterConfig == nil, "Dead letter config not yet supported")
|
||||
contract.Assertf(obj.VPCConfig == nil, "VPC config not yet supported")
|
||||
|
||||
// If an explicit name is given, use it. Otherwise, auto-generate a name in part based on the resource name.
|
||||
|
@ -110,12 +109,19 @@ func (p *funcProvider) Create(ctx context.Context, obj *lambda.Function) (resour
|
|||
Variables: aws.StringMap(*obj.Environment),
|
||||
}
|
||||
}
|
||||
var deadLetterConfig *awslambda.DeadLetterConfig
|
||||
if obj.DeadLetterConfig != nil {
|
||||
deadLetterConfig = &awslambda.DeadLetterConfig{
|
||||
TargetArn: aws.String(string(obj.DeadLetterConfig.Target)),
|
||||
}
|
||||
}
|
||||
|
||||
// Now go ahead and create the resource. Note that IAM profiles can take several seconds to propagate; see
|
||||
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role.
|
||||
fmt.Printf("Creating Lambda Function '%v' with name '%v'\n", *obj.Name, name)
|
||||
create := &awslambda.CreateFunctionInput{
|
||||
Code: code,
|
||||
DeadLetterConfig: deadLetterConfig,
|
||||
Description: obj.Description,
|
||||
Environment: env,
|
||||
FunctionName: aws.String(name),
|
||||
|
@ -189,6 +195,12 @@ func (p *funcProvider) Get(ctx context.Context, id resource.ID) (*lambda.Functio
|
|||
envmap := lambda.Environment(aws.StringValueMap(config.Environment.Variables))
|
||||
env = &envmap
|
||||
}
|
||||
var deadLetterConfig *lambda.DeadLetterConfig
|
||||
if config.DeadLetterConfig != nil {
|
||||
deadLetterConfig = &lambda.DeadLetterConfig{
|
||||
Target: resource.ID(aws.StringValue(config.DeadLetterConfig.TargetArn)),
|
||||
}
|
||||
}
|
||||
|
||||
return &lambda.Function{
|
||||
ARN: awscommon.ARN(aws.StringValue(config.FunctionArn)),
|
||||
|
@ -200,6 +212,7 @@ func (p *funcProvider) Get(ctx context.Context, id resource.ID) (*lambda.Functio
|
|||
Runtime: lambda.Runtime(aws.StringValue(config.Runtime)),
|
||||
FunctionName: config.FunctionName,
|
||||
Description: config.Description,
|
||||
DeadLetterConfig: deadLetterConfig,
|
||||
Environment: env,
|
||||
KMSKey: resource.MaybeID(config.KMSKeyArn),
|
||||
MemorySize: convutil.Int64PToFloat64P(config.MemorySize),
|
||||
|
@ -228,7 +241,7 @@ func (p *funcProvider) Update(ctx context.Context, id resource.ID,
|
|||
if diff.Changed(lambda.Function_Description) || diff.Changed(lambda.Function_Environment) ||
|
||||
diff.Changed(lambda.Function_Runtime) || diff.Changed(lambda.Function_Role) ||
|
||||
diff.Changed(lambda.Function_MemorySize) || diff.Changed(lambda.Function_Timeout) ||
|
||||
diff.Changed(lambda.Function_Environment) {
|
||||
diff.Changed(lambda.Function_Environment) || diff.Changed(lambda.Function_DeadLetterConfig) {
|
||||
|
||||
update := &awslambda.UpdateFunctionConfigurationInput{
|
||||
FunctionName: aws.String(name),
|
||||
|
@ -268,6 +281,13 @@ func (p *funcProvider) Update(ctx context.Context, id resource.ID,
|
|||
}
|
||||
}
|
||||
}
|
||||
if diff.Changed(lambda.Function_DeadLetterConfig) {
|
||||
if new.DeadLetterConfig != nil {
|
||||
update.DeadLetterConfig = &awslambda.DeadLetterConfig{
|
||||
TargetArn: aws.String(string(new.DeadLetterConfig.Target)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Updating Lambda function configuration '%v'\n", name)
|
||||
if _, retryerr := awsctx.RetryUntil(p.ctx, func() (bool, error) {
|
||||
|
|
|
@ -15,11 +15,13 @@ import (
|
|||
"github.com/pulumi/lumi/lib/aws/provider/awsctx"
|
||||
cloudwatchprovider "github.com/pulumi/lumi/lib/aws/provider/cloudwatch"
|
||||
iamprovider "github.com/pulumi/lumi/lib/aws/provider/iam"
|
||||
snsprovider "github.com/pulumi/lumi/lib/aws/provider/sns"
|
||||
"github.com/pulumi/lumi/lib/aws/provider/testutil"
|
||||
rpc "github.com/pulumi/lumi/lib/aws/rpc"
|
||||
"github.com/pulumi/lumi/lib/aws/rpc/cloudwatch"
|
||||
"github.com/pulumi/lumi/lib/aws/rpc/iam"
|
||||
"github.com/pulumi/lumi/lib/aws/rpc/lambda"
|
||||
"github.com/pulumi/lumi/lib/aws/rpc/sns"
|
||||
"github.com/pulumi/lumi/pkg/resource"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -54,6 +56,7 @@ func Test(t *testing.T) {
|
|||
Token: cloudwatchprovider.LogGroupToken},
|
||||
"filter": {Provider: cloudwatchprovider.NewLogSubscriptionFilterProvider(awsctx),
|
||||
Token: cloudwatchprovider.LogSubscriptionFilterToken},
|
||||
"deadlettertopic": {Provider: snsprovider.NewTopicProvider(awsctx), Token: snsprovider.TopicToken},
|
||||
}
|
||||
steps := []testutil.Step{
|
||||
{
|
||||
|
@ -81,6 +84,14 @@ func Test(t *testing.T) {
|
|||
}
|
||||
},
|
||||
},
|
||||
testutil.ResourceGenerator{
|
||||
Name: "deadlettertopic",
|
||||
Creator: func(ctx testutil.Context) interface{} {
|
||||
return &sns.Topic{
|
||||
Name: aws.String(prefix),
|
||||
}
|
||||
},
|
||||
},
|
||||
testutil.ResourceGenerator{
|
||||
Name: "f",
|
||||
Creator: func(ctx testutil.Context) interface{} {
|
||||
|
@ -90,6 +101,9 @@ func Test(t *testing.T) {
|
|||
Handler: "index.handler",
|
||||
Runtime: lambda.NodeJS6d10Runtime,
|
||||
Role: ctx.GetResourceID("role"),
|
||||
DeadLetterConfig: &lambda.DeadLetterConfig{
|
||||
Target: ctx.GetResourceID("deadlettertopic"),
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue