Skip to content

Commit

Permalink
go1.x to provided.al2 migration (#230)
Browse files Browse the repository at this point in the history
* provided.al2 migration
  • Loading branch information
msummers-nr authored Nov 17, 2023
1 parent 248be6d commit 482f297
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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~
Expand Down
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/github-repo/.rpdk-config
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 6 additions & 6 deletions examples/github-repo/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ _Required_: Yes

_Type_: String

_Minimum_: <code>1</code>
_Minimum Length_: <code>1</code>

_Maximum_: <code>50</code>
_Maximum Length_: <code>50</code>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

Expand All @@ -67,9 +67,9 @@ _Required_: No

_Type_: String

_Minimum_: <code>20</code>
_Minimum Length_: <code>20</code>

_Maximum_: <code>250</code>
_Maximum Length_: <code>250</code>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

Expand All @@ -81,9 +81,9 @@ _Required_: No

_Type_: String

_Minimum_: <code>20</code>
_Minimum Length_: <code>20</code>

_Maximum_: <code>250</code>
_Maximum Length_: <code>250</code>

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

Expand Down
7 changes: 7 additions & 0 deletions examples/github-repo/resource-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions examples/github-repo/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/
8 changes: 4 additions & 4 deletions python/rpdk/go/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion python/rpdk/go/templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion python/rpdk/go/templates/makebuild
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 482f297

Please sign in to comment.