From 44fad1561d84aa39e9eccf94fc11dce92a68fdce Mon Sep 17 00:00:00 2001 From: Mike Summers Date: Mon, 13 Nov 2023 06:06:10 -0600 Subject: [PATCH 1/4] provided.al2 migration --- .pre-commit-config.yaml | 3 --- examples/github-repo/.rpdk-config | 6 +++--- examples/github-repo/cmd/resource/config.go | 19 +++++++++++++++++++ examples/github-repo/docs/README.md | 12 ++++++------ examples/github-repo/makebuild | 8 ++++++++ examples/github-repo/resource-role.yaml | 7 +++++++ examples/github-repo/template.yml | 16 ++++++++++++---- python/rpdk/go/codegen.py | 8 ++++---- python/rpdk/go/templates/Makefile | 2 +- python/rpdk/go/templates/makebuild | 2 +- 10 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 examples/github-repo/cmd/resource/config.go create mode 100644 examples/github-repo/makebuild diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 743c5b58..c1c0a715 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -64,9 +64,6 @@ repos: description: Run pytest in the local virtualenv entry: > pytest - --cov-report=term - --cov-report=html - --cov="rpdk.go" --durations=5 "tests/" language: system diff --git a/examples/github-repo/.rpdk-config b/examples/github-repo/.rpdk-config index 4b0229e2..ed877e7e 100644 --- a/examples/github-repo/.rpdk-config +++ b/examples/github-repo/.rpdk-config @@ -1,9 +1,9 @@ { "typeName": "Example::GitHub::Repo", "language": "go", - "runtime": "go1.x", - "entrypoint": "handler", - "testEntrypoint": "handler", + "runtime": "provided.al2", + "entrypoint": "bootstrap", + "testEntrypoint": "bootstrap", "settings": { "import_path": "github.com/aws-cloudformation/cloudformation-cli-go-plugin/examples/github-repo", "protocolVersion": "2.0.0", diff --git a/examples/github-repo/cmd/resource/config.go b/examples/github-repo/cmd/resource/config.go new file mode 100644 index 00000000..4d9eb783 --- /dev/null +++ b/examples/github-repo/cmd/resource/config.go @@ -0,0 +1,19 @@ +// Code generated by 'cfn generate', changes will be undone by the next invocation. DO NOT EDIT. +// Updates to this type are made my editing the schema file and executing the 'generate' command. +package resource + +import "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" + +// TypeConfiguration is autogenerated from the json schema +type TypeConfiguration struct { +} + +// Configuration returns a resource's configuration. +func Configuration(req handler.Request) (*TypeConfiguration, error) { + // Populate the type configuration + typeConfig := &TypeConfiguration{} + if err := req.UnmarshalTypeConfig(typeConfig); err != nil { + return typeConfig, err + } + return typeConfig, nil +} diff --git a/examples/github-repo/docs/README.md b/examples/github-repo/docs/README.md index bda31814..11ddd99f 100644 --- a/examples/github-repo/docs/README.md +++ b/examples/github-repo/docs/README.md @@ -43,9 +43,9 @@ _Required_: Yes _Type_: String -_Minimum_: 1 +_Minimum Length_: 1 -_Maximum_: 50 +_Maximum Length_: 50 _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) @@ -67,9 +67,9 @@ _Required_: No _Type_: String -_Minimum_: 20 +_Minimum Length_: 20 -_Maximum_: 250 +_Maximum Length_: 250 _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) @@ -81,9 +81,9 @@ _Required_: No _Type_: String -_Minimum_: 20 +_Minimum Length_: 20 -_Maximum_: 250 +_Maximum Length_: 250 _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) diff --git a/examples/github-repo/makebuild b/examples/github-repo/makebuild new file mode 100644 index 00000000..c9c09e86 --- /dev/null +++ b/examples/github-repo/makebuild @@ -0,0 +1,8 @@ +# This file is autogenerated, do not edit; +# changes will be undone by the next 'generate' command. + +.PHONY: build +build: + cfn generate + #env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="$(TAGS)" -o bin/handler cmd/main.go + env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="lambda.norpc,$(TAGS)" -o bin/bootstrap cmd/main.go #local diff --git a/examples/github-repo/resource-role.yaml b/examples/github-repo/resource-role.yaml index a9a2bd77..88f02a39 100644 --- a/examples/github-repo/resource-role.yaml +++ b/examples/github-repo/resource-role.yaml @@ -15,6 +15,13 @@ Resources: Principal: Service: resources.cloudformation.amazonaws.com Action: sts:AssumeRole + Condition: + StringEquals: + aws:SourceAccount: + Ref: AWS::AccountId + StringLike: + aws:SourceArn: + Fn::Sub: arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:type/resource/Example-GitHub-Repo/* Path: "/" Policies: - PolicyName: ResourceTypePolicy diff --git a/examples/github-repo/template.yml b/examples/github-repo/template.yml index b3be0416..806b6412 100644 --- a/examples/github-repo/template.yml +++ b/examples/github-repo/template.yml @@ -9,9 +9,13 @@ Globals: Resources: TypeFunction: Type: AWS::Serverless::Function + Metadata: + BuildMethod: go1.x Properties: - Handler: handler - Runtime: go1.x + Handler: bootstrap + Runtime: provided.al2 + Architectures: + - x86_64 CodeUri: bin/ # Uncomment to test with AWS resources # Environment: @@ -20,7 +24,11 @@ Resources: TestEntrypoint: Type: AWS::Serverless::Function + Metadata: + BuildMethod: go1.x Properties: - Handler: handler - Runtime: go1.x + Handler: bootstrap + Runtime: provided.al2 + Architectures: + - x86_64 CodeUri: bin/ diff --git a/python/rpdk/go/codegen.py b/python/rpdk/go/codegen.py index ea79249f..3d6f980d 100644 --- a/python/rpdk/go/codegen.py +++ b/python/rpdk/go/codegen.py @@ -32,9 +32,9 @@ class GoExecutableNotFoundError(SysExitRecommendedError): class GoLanguagePlugin(LanguagePlugin): MODULE_NAME = __name__ NAME = "go" - RUNTIME = "go1.x" - ENTRY_POINT = "handler" - TEST_ENTRY_POINT = "handler" + RUNTIME = "provided.al2" + ENTRY_POINT = "bootstrap" + TEST_ENTRY_POINT = "bootstrap" CODE_URI = "bin/" def __init__(self): @@ -251,7 +251,7 @@ def pre_package(project: Project): @staticmethod def _find_exe(project: Project): - exe_glob = list((project.root / "bin").glob("handler")) + exe_glob = list((project.root / "bin").glob("bootstrap")) if not exe_glob: LOG.debug("No Go executable match") raise GoExecutableNotFoundError( diff --git a/python/rpdk/go/templates/Makefile b/python/rpdk/go/templates/Makefile index bc13ba53..61819cb0 100644 --- a/python/rpdk/go/templates/Makefile +++ b/python/rpdk/go/templates/Makefile @@ -5,7 +5,7 @@ build: test: cfn generate - env GOOS=linux go build -ldflags="-s -w" -o bin/handler cmd/main.go + env GOOS=linux go build -ldflags="-s -w" -tags="lambda.norpc,$(TAGS)" -o bin/bootstrap cmd/main.go clean: rm -rf bin diff --git a/python/rpdk/go/templates/makebuild b/python/rpdk/go/templates/makebuild index 390b673b..a59b4784 100644 --- a/python/rpdk/go/templates/makebuild +++ b/python/rpdk/go/templates/makebuild @@ -4,4 +4,4 @@ .PHONY: build build: cfn generate - env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="$(TAGS)" -o bin/handler cmd/main.go + env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="lambda.norpc,$(TAGS)" -o bin/bootstrap cmd/main.go From 60353a9153e5da0e55154d2f31a7cb301cb193c7 Mon Sep 17 00:00:00 2001 From: Mike Summers Date: Mon, 13 Nov 2023 06:19:15 -0600 Subject: [PATCH 2/4] provided.al2 migration --- examples/github-repo/makebuild | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/github-repo/makebuild b/examples/github-repo/makebuild index c9c09e86..5369cf94 100644 --- a/examples/github-repo/makebuild +++ b/examples/github-repo/makebuild @@ -4,5 +4,4 @@ .PHONY: build build: cfn generate - #env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="$(TAGS)" -o bin/handler cmd/main.go - env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="lambda.norpc,$(TAGS)" -o bin/bootstrap cmd/main.go #local + env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="lambda.norpc,$(TAGS)" -o bin/bootstrap cmd/main.go \ No newline at end of file From e56d98e08f4880b086a43bbd29d97ae064cbd246 Mon Sep 17 00:00:00 2001 From: Mike Summers Date: Fri, 17 Nov 2023 05:57:44 -0600 Subject: [PATCH 3/4] CI/CD fixes --- .gitignore | 4 ++++ examples/github-repo/cmd/resource/config.go | 19 ------------------- examples/github-repo/docs/README.md | 1 + examples/github-repo/makebuild | 7 ------- 4 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 examples/github-repo/cmd/resource/config.go delete mode 100644 examples/github-repo/makebuild diff --git a/.gitignore b/.gitignore index 01ddf1bd..909c95fe 100644 --- a/.gitignore +++ b/.gitignore @@ -117,6 +117,10 @@ out.java out/ tmp/ +# generated files +examples/github-repo/makebuild +examples/github-repo/cmd/resource/config.go + # Binaries for programs and plugins *.exe *.exe~ diff --git a/examples/github-repo/cmd/resource/config.go b/examples/github-repo/cmd/resource/config.go deleted file mode 100644 index 4d9eb783..00000000 --- a/examples/github-repo/cmd/resource/config.go +++ /dev/null @@ -1,19 +0,0 @@ -// Code generated by 'cfn generate', changes will be undone by the next invocation. DO NOT EDIT. -// Updates to this type are made my editing the schema file and executing the 'generate' command. -package resource - -import "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - -// TypeConfiguration is autogenerated from the json schema -type TypeConfiguration struct { -} - -// Configuration returns a resource's configuration. -func Configuration(req handler.Request) (*TypeConfiguration, error) { - // Populate the type configuration - typeConfig := &TypeConfiguration{} - if err := req.UnmarshalTypeConfig(typeConfig); err != nil { - return typeConfig, err - } - return typeConfig, nil -} diff --git a/examples/github-repo/docs/README.md b/examples/github-repo/docs/README.md index 11ddd99f..95acc75d 100644 --- a/examples/github-repo/docs/README.md +++ b/examples/github-repo/docs/README.md @@ -112,3 +112,4 @@ For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::G #### URL URL to the repository + diff --git a/examples/github-repo/makebuild b/examples/github-repo/makebuild deleted file mode 100644 index 5369cf94..00000000 --- a/examples/github-repo/makebuild +++ /dev/null @@ -1,7 +0,0 @@ -# This file is autogenerated, do not edit; -# changes will be undone by the next 'generate' command. - -.PHONY: build -build: - cfn generate - env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -tags="lambda.norpc,$(TAGS)" -o bin/bootstrap cmd/main.go \ No newline at end of file From fdb582527e12ae7ebcac964194e06252717e9ee3 Mon Sep 17 00:00:00 2001 From: Mike Summers Date: Fri, 17 Nov 2023 11:25:15 -0600 Subject: [PATCH 4/4] CI/CD fixes --- examples/github-repo/docs/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/github-repo/docs/README.md b/examples/github-repo/docs/README.md index 95acc75d..11ddd99f 100644 --- a/examples/github-repo/docs/README.md +++ b/examples/github-repo/docs/README.md @@ -112,4 +112,3 @@ For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::G #### URL URL to the repository -