Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go1.x to provided.al2 migration #230

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 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
19 changes: 19 additions & 0 deletions examples/github-repo/cmd/resource/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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/makebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the extra condition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason this is only x86_64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't clear to me what to do here, particularly as it's an example.

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
Loading