aws-extensions-for-dotnet-cli icon indicating copy to clipboard operation
aws-extensions-for-dotnet-cli copied to clipboard

Deploying existing docker image

Open timdinhdotcom opened this issue 3 years ago • 1 comments

If I ran the command below, it will build a docker image then push it to ECR and perform other steps.

dotnet lambda deploy-serverless --stack-name my-app

I have a project which I must use docker buildx build . command to create a docker image. Is there a way to tell deploy-serverless to use existing image instead?

Describe the Feature

Allow user to specify an existing image when deploying lambda serverless with the command dotnet lambda deploy-serverless command.

Maybe add a parameter called --use-image?

Is your Feature Request related to a problem?

Proposed Solution

I have a project which I must use docker buildx build . command to create a docker image. There is no way to deploy this image with dotnet lambda deploy-serverless command

Describe alternatives you've considered

Maybe manually deploy the image to ECR then manually changing the Lambda configuration to use the new image?

Additional Context

I have an Apple M1 MacBook and trying to deploy an x64 image. The command dotnet lambda deploy-serverless only create image for arm64 architecture. I need an x64 image so I have to use docker buildx build command to create an x64 image.

Environment

Developer environment is Apple M1 MacBook (arm64 architecture)

Target environment is AWS serverless (x64 architecture). AWS do offer arm64 lambda serverless too but one of the project had native dependency on x64 and is it not possible to run it on arm64.

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

timdinhdotcom avatar Dec 04 '21 01:12 timdinhdotcom

When deploying the serverless application using Image package type, serverless.template has AspNetCoreFunction resource with ImageUri as one of the properties. For example:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Transform": "AWS::Serverless-2016-10-31",
  "Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
  "Parameters": {},
  "Conditions": {},
  "Resources": {
    "AspNetCoreFunction": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "PackageType": "Image",
        "ImageConfig": {
          "EntryPoint": [
            "/lambda-entrypoint.sh"
          ],
          "Command": [
            "AWSServerlessNET5::AWSServerlessNET5.LambdaEntryPoint::FunctionHandlerAsync"
          ]
        },
        "ImageUri": "",
        "MemorySize": 256,
        "Timeout": 30,
        "Role": null,
        "Policies": [
          "AWSLambda_FullAccess"
        ],
        "Events": {
          "ProxyResource": {
            "Type": "Api",
            "Properties": {
              "Path": "/{proxy+}",
              "Method": "ANY"
            }
          },
          "RootResource": {
            "Type": "Api",
            "Properties": {
              "Path": "/",
              "Method": "ANY"
            }
          }
        }
      },
      "Metadata": {
        "Dockerfile": "Dockerfile",
        "DockerContext": ".",
        "DockerTag": ""
      }
    }
  },
  "Outputs": {
    "ApiURL": {
      "Description": "API endpoint URL for Prod environment",
      "Value": {
        "Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
      }
    }
  }
}

Not sure if setting ImageUri property would provide workaround for user. Needs review with the team.

ashishdhingra avatar Jan 28 '22 23:01 ashishdhingra

This is being tracked as part of issue https://github.com/aws/aws-extensions-for-dotnet-cli/issues/264. The ImageUri used to work in version 4.3.0 of Amazon.Lambda.Tools, but not working in latest version.

Also take note of findings in https://github.com/aws/aws-extensions-for-dotnet-cli/issues/264#issuecomment-1471000563. Per https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-imageuri, Building your application with necessary Metadata entries takes precedence over ImageUri, so if you specify both then ImageUri is ignored.. So ImageUri scenario kicks in if Metadata is not present.

ashishdhingra avatar Mar 16 '23 16:03 ashishdhingra

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Mar 16 '23 16:03 github-actions[bot]