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

golang aws templates refer to go1.x runtime which is being depreciated #12123

Open
4 tasks done
jvsteiner opened this issue Aug 26, 2023 · 18 comments
Open
4 tasks done

golang aws templates refer to go1.x runtime which is being depreciated #12123

jvsteiner opened this issue Aug 26, 2023 · 18 comments

Comments

@jvsteiner
Copy link

Are you certain it's a bug?

  • Yes, it looks like a bug

Is the issue caused by a plugin?

  • It is not a plugin issue

Are you using the latest v3 release?

  • Yes, I'm using the latest v3 release

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

I got a message today that the existing "go1.x" runtime is being depreciated, and replaced with a new provided.al2 runtime. AWS has published instructions on how to migrate here - some of which would likely involve modifying how the handler and entrypoint are referred to in the serverless.yaml file. I upgrade serverless to latest, but I still see that new projects are created with the old runtime, despite it being depreciated early next year.

Service configuration (serverless.yml) content

N/A

Command name and used flags

N/A

Command output

N/A

Environment information

$ serverless --version
Framework Core: 3.34.0
Plugin: 6.2.3
SDK: 4.3.2
@Fyb3roptik
Copy link

Here for this as well

@ShiriNmi1520
Copy link

I second that as I received a deprecated notice from aws.

@ShiriNmi1520
Copy link

ShiriNmi1520 commented Aug 27, 2023

As I tested so far, simply change the runtime can still make deployment succes, however, when I trying to test it by simply making http request to it, I got the following error.
Maybe the further change is required 🥲

Errors

{"message":"Internal Server Error"}

Output logs

# myawesomeproject git:awesome-branch ● [^._.^]ノ彡ミ彡ミ
$ serverless --org=shirinmi


✔ Your project is ready to be deployed to Serverless Dashboard (org: "myorg", app: "myawesomeproject")

? Do you want to deploy now? Yes

Deploying myawesomeproject to stage dev (ap-southeast-1)
Warning: Serverless Dashboard monitoring features do not support the following runtime: provided.al2

✔ Service deployed to stack myawesomeproject-dev (123s)

console: https://console.serverless.com/shirinmi/metrics/awsLambda?globalEnvironments=dev&globalNamespace= myawesomeproject&globalRegions=ap-southeast-1&globalScope=awsLambda&globalTimeFrame=15m
dashboard: dashboard-url
endpoints:
  GET - endpoint1
  GET - endpoint2
functions:
  hello: myawesomeproject-dev-hello (5.9 MB)
  world: myawesomeproject-dev-world (5.9 MB)

What next?
Run these commands in the project directory:

serverless deploy    Deploy changes
serverless info      View deployed endpoints and resources
serverless invoke    Invoke deployed functions
serverless --help    Discover more commands

Serverless configuration file

# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
#    docs.serverless.com
#
# Happy Coding!

service: myawesomeservice
# app and org for use with dashboard.serverless.com
app: myawesomeproject
org: myorg

configValidationMode: error

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: '3'

provider:
  name: aws
  runtime: provided.al2
  stage: dev
  region: ap-southeast-1

# you can add statements to the Lambda function's IAM Role here
#  iam:
#    role:
#      statements:
#        - Effect: "Allow"
#          Action:
#            - "s3:ListBucket"
#          Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ]  }
#        - Effect: "Allow"
#          Action:
#            - "s3:PutObject"
#          Resource:
#            Fn::Join:
#              - ""
#              - - "arn:aws:s3:::"
#                - "Ref" : "ServerlessDeploymentBucket"
#                - "/*"

# you can define service wide environment variables here
#  environment:
#    variable1: value1

package:
  patterns:
    - '!./**'
    - ./bin/**

functions:
  hello:
    handler: bin/hello
    events:
      - httpApi:
          path: /hello
          method: get
  world:
    handler: bin/world
    events:
      - httpApi:
          path: /world
          method: get
#    The following are a few example events you can configure
#    NOTE: Please make sure to change your handler code to work with those events
#    Check the event documentation for details
# events:
#    events:
#      - http:
#          path: users/create
#          method: get
#      - websocket: $connect
#      - s3: ${env:BUCKET}
#      - schedule: rate(10 minutes)
#      - sns: greeter-topic
#      - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
#      - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
#      - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
#      - iot:
#          sql: "SELECT * FROM 'some_topic'"
#      - cloudwatchEvent:
#          event:
#            source:
#              - "aws.ec2"
#            detail-type:
#              - "EC2 Instance State-change Notification"
#            detail:
#              state:
#                - pending
#      - cloudwatchLog: '/aws/lambda/hello'
#      - cognitoUserPool:
#          pool: MyUserPool
#          trigger: PreSignUp
#      - alb:
#          listenerArn: arn:aws:elasticloadbalancing:us-east-1:XXXXXX:listener/app/my-load-balancer/50dc6c495c0c9188/
#          priority: 1
#          conditions:
#            host: example.com
#            path: /hello

#    Define function environment variables here
#    environment:
#      variable2: value2

# you can add CloudFormation resource templates here
#resources:
#  Resources:
#    NewResource:
#      Type: AWS::S3::Bucket
#      Properties:
#        BucketName: my-new-bucket
#  Outputs:
#     NewOutput:
#       Description: "Description for the output"
#       Value: "Some output value"

@Fyb3roptik
Copy link

You have to name the binary specifically. Check that doc

@ribtoks
Copy link

ribtoks commented Aug 28, 2023

You have to name the binary specifically

Regarding this. Would be great if Serverless allowed to rename the binary automatically. It's quite annoying to start managing it if you're deploying more than 1 binary and they are stored (typically) in the common ./bin/ dir

@yasuto-nishii
Copy link

yasuto-nishii commented Aug 28, 2023

I have the same concern. I'm creating different binary name per function like ./bin/func1 and ./bin/func2, and deploying them. However, provided.al2 does not allow this and forces me to name everything bootstrap.

@Fyb3roptik
Copy link

Fyb3roptik commented Sep 11, 2023

Maybe we could just do ./bin/func1/bootstrap? Using the folder structure to know which one to use?

@jvsteiner
Copy link
Author

Something like ./bin/func1/bootstrap was what I was hoping to see - makes sense

@ribtoks
Copy link

ribtoks commented Sep 15, 2023

Using ./bin/func1/bootstrap is annoying locally. Of course you can make this workaround today, but I think it will be much friendlier if serverless framework will package it for you like this. Zip archive is created by serverless so it should be easy to create file in the archive with a different mapping.

@jvsteiner
Copy link
Author

What is annoying about it? What folder structure locally would you propose? I understanding you have in mind that you could maybe have binaries ./bin/func1 and ./bin/func2 locally, and then package them as ./bin/func1/bootstrap and ./bin/func1/bootstrap in the container, but what is the benefit?

@ribtoks
Copy link

ribtoks commented Sep 15, 2023

Personally for me, the benefits are:

  • having all binaries in a single directory which is prefixed to the $PATH when I need it
  • clarity when I do ls what is what
  • lambda and non-lambda binaries in the single directory
  • consistency in the Makefile

What is annoying is the (anticipated) absence of such benefits.

Answering your question about proposed folder structure, the main thing I propose is to NOT make changes to folder structure, but serverless framework packaging function ./bin/func1 as ./bin/func1/bootstrap in the .zip (it's easy to change prefix, when you zip via API).

@Fyb3roptik
Copy link

Agreed with the above 100%, just saying as a workaround is all. I hope serverless handles this in the build process

@yasuto-nishii
Copy link

yasuto-nishii commented Sep 21, 2023

I agree as well. For now, I'm developing Makefile to do above process as a workaround.

@slatermorgan
Copy link

I have updated my function to

functions:
  healthcheck:
    handler: bin/lambda/functions/healthcheck/bootstrap
    timeout: 10
    events:
      - http:
          path: /_health
          method: get
          private: true
    documentation:
      summary: "Health check"
      description: "Health check endpoint"
      methodResponses:
        - statusCode: "200"

Aswell as my provider.runtime to provided.al2

And updated my go build script to run:
GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/lambda/functions/healthcheck/bootstrap lambda/functions/healthcheck/main.go

But I'm getting:

Serverless: Excluding development dependencies...
 
  Serverless Error ---------------------------------------
 
  No file matches include / exclude patterns

@alock
Copy link

alock commented Oct 31, 2023

From my understanding of the required migration you can no longer pass a binary into the runtime. This blogpost by @matthiasbruns helped me out a bunch (thanks!)

changes to our build logic:

GOOS=linux GOARCH=arm64 go build -ldflags -s -d -w -tags lambda.norpc -mod=readonly -o bin/function/bootstrap cmd/function/main.go
zip -j bin/function.zip bin/function/bootstrap

changes to our serverless files where below:

provider:
  name: aws
  runtime: provided.al2
  architecture: arm64
...
package:
  individually: true
...
functions:
  function:
    handler: bootstrap
    package:
      artifact: bin/function.zip
...

@slatermorgan
Copy link

Thanks I actually managed to overcome my issues with the amazing serverless-go-plugin

@Fyb3roptik
Copy link

Can someone from serverless address this?!

@Pauloricardo2019
Copy link

Can someone help me?
I'm doing the migration.
My Makefile looks like this:

build:
@ go fmt ./...
@ go vet ./...
@ env GOARCH=amd64 GOOS=linux CGO_ENABLED=0 GO_DISTFLAGS=--enable-all-static go build -tags lambda.norpc -o ./bin/bootstrap -tags netgo -ldflags '-extldflags "-static"' ./adapter/aws/lambda/api/main.go
@ cd bin && zip -j bootstrap.zip bootstrap || true

And my serverless configuration function looks like this:

functions:
core-api:
name: ${self:service}-api
description: Core API
handler: bootstrap
package:
artifact: bin/bootstrap.zip
events:
- http:
path: /
method: ANY
- http:
path: /{any+}
method: ANY

It builds and deploys normally, but I'm getting this error when accessing the route:
aws error:
{
"errorType": "Runtime.InvalidEntrypoint",
"errorMessage": "RequestId: 195b05c5-40ec-45cd-a34c-efb453df96b6 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"
}

How can I solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants