Skip to content

Commit e4381ea

Browse files
committed
Add pulumi.Asset support to lambda function
1 parent d664069 commit e4381ea

File tree

21 files changed

+159
-71
lines changed

21 files changed

+159
-71
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## HEAD (Unreleased)
22

3+
- Add lambda.Function support for pulumi Assets [#182](https://github.com/pulumi/pulumi-aws-native/pull/182)
4+
35
## 0.2.0 (October 8, 2021)
46

57
- Deduplicate type names [#160](https://github.com/pulumi/pulumi-aws-native/issues/160)

examples/aws-native-ts-stepfunctions/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ const worldFunction = new awsnative.lambda.Function('worldFunction',
4545
runtime: "nodejs14.x",
4646
handler: "index.handler",
4747
code: {
48-
zipFile: `exports.handler = function(event, context, callback){
49-
var response = event.response;
50-
const updated = { "response": response + "World!" };
51-
callback(null, updated);
52-
};`,
48+
zipFile: new pulumi.asset.FileAsset("world_function.js"),
5349
},
5450
}, {dependsOn: lambdaRolePolicy});
5551

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exports.handler = function(event, context, callback){
2+
var response = event.response;
3+
const updated = { "response": response + "World!" };
4+
callback(null, updated);
5+
};

examples/simple-ts/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
// Copyright 2016-2021, Pulumi Corporation.
1+
/*
2+
* Copyright 2016-2021, Pulumi Corporation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

317
import * as aws from "@pulumi/aws-native";
418
import * as random from "@pulumi/random";

provider/cmd/cf2pulumi/schema-full.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44953,7 +44953,7 @@
4495344953
"description": "For versioned objects, the version of the deployment package object to use."
4495444954
},
4495544955
"zipFile": {
44956-
"type": "string",
44956+
"$ref": "pulumi.json#/Asset",
4495744957
"description": "The source code of your Lambda function. If you include your function source inline with this parameter, AWS CloudFormation places it in a file named index and zips it to create a deployment package.."
4495844958
}
4495944959
},

provider/cmd/pulumi-resource-aws-native/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45159,7 +45159,7 @@
4515945159
"description": "For versioned objects, the version of the deployment package object to use."
4516045160
},
4516145161
"zipFile": {
45162-
"type": "string",
45162+
"$ref": "pulumi.json#/Asset",
4516345163
"description": "The source code of your Lambda function. If you include your function source inline with this parameter, AWS CloudFormation places it in a file named index and zips it to create a deployment package.."
4516445164
}
4516545165
}

provider/cmd/pulumi-resource-aws-native/schema.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

provider/go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,9 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
485485
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
486486
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
487487
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
488-
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
489488
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
489+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
490+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
490491
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
491492
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
492493
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=

provider/pkg/provider/provider.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (p *cfnProvider) DiffConfig(ctx context.Context, req *pulumirpc.DiffRequest
235235
news, err := plugin.UnmarshalProperties(req.GetNews(), plugin.MarshalOptions{
236236
Label: fmt.Sprintf("%s.news", label),
237237
KeepUnknowns: true,
238-
RejectAssets: true,
238+
RejectAssets: false,
239239
})
240240
if err != nil {
241241
return nil, errors.Wrapf(err, "diffConfig failed because of malformed resource inputs")
@@ -511,7 +511,7 @@ func (p *cfnProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (*
511511
newInputs, err := plugin.UnmarshalProperties(req.GetNews(), plugin.MarshalOptions{
512512
Label: fmt.Sprintf("%s.properties", label),
513513
KeepUnknowns: true,
514-
RejectAssets: true,
514+
RejectAssets: false,
515515
KeepSecrets: true,
516516
})
517517
if err != nil {
@@ -579,7 +579,7 @@ func (p *cfnProvider) Create(ctx context.Context, req *pulumirpc.CreateRequest)
579579
inputs, err := plugin.UnmarshalProperties(req.GetProperties(), plugin.MarshalOptions{
580580
Label: fmt.Sprintf("%s.properties", label),
581581
KeepUnknowns: true,
582-
RejectAssets: true,
582+
RejectAssets: false,
583583
KeepSecrets: true,
584584
})
585585
if err != nil {
@@ -611,7 +611,10 @@ func (p *cfnProvider) Create(ctx context.Context, req *pulumirpc.CreateRequest)
611611
cfType = spec.CfType
612612

613613
// Convert SDK inputs to CFN payload.
614-
payload = schema.SdkToCfn(&spec, p.resourceMap.Types, inputs.MapRepl(nil, mapReplStripSecrets))
614+
payload, err = schema.SdkToCfn(&spec, p.resourceMap.Types, inputs.MapRepl(nil, mapReplStripSecrets))
615+
if err != nil {
616+
return nil, fmt.Errorf("failed to convert SDK inputs to CFN: %w", err)
617+
}
615618
}
616619

617620
// Serialize inputs as a desired state JSON.
@@ -814,7 +817,7 @@ func (p *cfnProvider) Update(ctx context.Context, req *pulumirpc.UpdateRequest)
814817
newInputs, err := plugin.UnmarshalProperties(req.GetNews(), plugin.MarshalOptions{
815818
Label: fmt.Sprintf("%s.newInputs", label),
816819
KeepUnknowns: true,
817-
RejectAssets: true,
820+
RejectAssets: false,
818821
KeepSecrets: true,
819822
})
820823
if err != nil {
@@ -1001,7 +1004,7 @@ func (p *cfnProvider) diffState(olds *pbstruct.Struct, news *pbstruct.Struct, la
10011004
oldState, err := plugin.UnmarshalProperties(olds, plugin.MarshalOptions{
10021005
Label: fmt.Sprintf("%s.oldState", label),
10031006
KeepUnknowns: true,
1004-
RejectAssets: true,
1007+
RejectAssets: false,
10051008
KeepSecrets: true,
10061009
})
10071010
if err != nil {
@@ -1014,7 +1017,7 @@ func (p *cfnProvider) diffState(olds *pbstruct.Struct, news *pbstruct.Struct, la
10141017
newInputs, err := plugin.UnmarshalProperties(news, plugin.MarshalOptions{
10151018
Label: fmt.Sprintf("%s.newInputs", label),
10161019
KeepUnknowns: true,
1017-
RejectAssets: true,
1020+
RejectAssets: false,
10181021
KeepSecrets: true,
10191022
})
10201023
if err != nil {

0 commit comments

Comments
 (0)