[{"data":1,"prerenderedAt":65},["ShallowReactive",2],{"content-guides-serverless-crossplane-on-eks-docker-image":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":11,"contributorPaths":12,"menuType":14,"contentName":15,"slug":16,"readingTime":17,"menu":18,"nextDocItem":39,"previousDocItem":22},"\u003Cp>In this module, we will be building a Docker image with a sample application, creating an ECR repository, and uploading the image to it. This container image contains the source code for the Lambda function that is part of the serverless application we will be deploying later on in this tutorial.\u003C\u002Fp>\n\u003Ch2>Implementation\u003C\u002Fh2>\n\u003Cp>Clone the \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fcrossplane-on-eks\u002Ftree\u002Fmain\">crossplane-on-eks\u003C\u002Fa> repository to your local machine.\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">git clone https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fcrossplane-on-eks.git\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Navigate to the function code folder\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">cd crossplane-on-eks\u002Fexamples\u002Fupbound-aws-provider\u002Fcomposite-resources\u002Fserverless-examples\u002Fobject-processor-app \n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Set AWS_REGION, ECR_URL, and IMAGE_NAME as environment variables.\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">export AWS_REGION=&lt;replace-me-with-aws-region&gt; # example `us-east-1`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cpre>\u003Ccode class=\"language-sh\">export ECR_URL=$(aws sts get-caller-identity --output json | jq -r &quot;.Account&quot; | tr -d &#39;[:space:]&#39;).dkr.ecr.$AWS_REGION.amazonaws.com\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cpre>\u003Ccode class=\"language-sh\">export IMAGE_NAME=&lt;replace-me-with-image-name&gt; # example `lambda-test`\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Log in to ECR\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_URL\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Create ECR repository\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">aws ecr create-repository --repository-name $IMAGE_NAME\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Build the Go binary\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Set the DOCKER_IMAGE env var. This step is necessary to properly escape the &#39;:&#39; for the subsequent docker commands\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">export DOCKER_IMAGE=$ECR_URL\u002F$IMAGE_NAME\\:latest\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Build the docker image\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">docker build -t $DOCKER_IMAGE . \n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Expected output\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">[+] Building 0.5s (7\u002F7) FINISHED\n =&gt; [internal] load build definition from Dockerfile                                                             0.0s\n =&gt; =&gt; transferring dockerfile: 37B                                                                              0.0s\n =&gt; [internal] load .dockerignore                                                                                0.0s\n =&gt; =&gt; transferring context: 2B                                                                                  0.0s\n =&gt; [internal] load metadata for public.ecr.aws\u002Flambda\u002Fgo:1                                                      0.3s\n =&gt; [internal] load build context                                                                                0.1s\n =&gt; =&gt; transferring context: 13.18MB                                                                             0.1s\n =&gt; [1\u002F2] FROM public.ecr.aws\u002Flambda\u002Fgo:1@sha256:ea8389f1a5e7e9d29c4d65008da143985bef131cf901db63ab57e4124f7f66  0.0s\n =&gt; CACHED [2\u002F2] COPY main \u002Fvar\u002Ftask                                                                             0.0s\n =&gt; exporting to image                                                                                           0.0s\n =&gt; =&gt; exporting layers                                                                                          0.0s\n =&gt; =&gt; writing image sha256:0f3ea389fa4f3761f25b2b666a8f49b458e825f1180b9c2181ecadd55fd2cc9a                     0.0s\n =&gt; =&gt; naming to 111122223333.dkr.ecr.us-east-1.amazonaws.com\u002Flambda-test:latest\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Upload the docker image to ECR\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">docker push $DOCKER_IMAGE\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Expected output\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-sh\">The push refers to repository [111122223333.dkr.ecr.us-east-1.amazonaws.com\u002Flambda-test]\n8ce4b9b80622: Pushed\n02c5912fad21: Pushed\n2d244e0816c6: Pushed\n2b58bd9b1feb: Pushed\nd79a81893db4: Pushed\n2ad9f6dfcb67: Pushed\nlatest: digest: sha256:86bb30cbf14d9ac538946cdd9565f09b7a4a0b9846e28a73cd27116280c0a58e size: 1579\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Ch2>Conclusion\u003C\u002Fh2>\n\u003Cp>In this module, we covered how to build a Docker image, create an ECR repo, and upload an image to it. In the next module, we will learn how to deploy the serverless application.\u003C\u002Fp>\n",{"title":6,"order":7,"learningGoals":8},"1. Build a docker image and push to ECR",2,[9,10],"Building a Docker image from a given application","Creating an ECR repo and uploading an image to it using the AWS CLI","In this module, we will be building a Docker image with a sample application, creating an ECR repository, and uploading the image to it. This container image contains the source code for the Lambda function that is part of the serverless application we will be deploying later on in this tutorial.\n\n## Implementation\n\nClone the [crossplane-on-eks](https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fcrossplane-on-eks\u002Ftree\u002Fmain) repository to your local machine.\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002Fawslabs\u002Fcrossplane-on-eks.git\n```\n\nNavigate to the function code folder\n\n```sh\ncd crossplane-on-eks\u002Fexamples\u002Fupbound-aws-provider\u002Fcomposite-resources\u002Fserverless-examples\u002Fobject-processor-app \n```\n\nSet AWS_REGION, ECR_URL, and IMAGE_NAME as environment variables.\n\n```sh\nexport AWS_REGION=\u003Creplace-me-with-aws-region> # example `us-east-1`\n```\n\n```sh\nexport ECR_URL=$(aws sts get-caller-identity --output json | jq -r \".Account\" | tr -d '[:space:]').dkr.ecr.$AWS_REGION.amazonaws.com\n```\n\n```sh\nexport IMAGE_NAME=\u003Creplace-me-with-image-name> # example `lambda-test`\n```\n\nLog in to ECR\n\n```sh\naws ecr get-login-password | docker login --username AWS --password-stdin $ECR_URL\n```\n\nCreate ECR repository\n\n```sh\naws ecr create-repository --repository-name $IMAGE_NAME\n```\n\nBuild the Go binary\n\n```sh\nGOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go\n```\n\nSet the DOCKER_IMAGE env var. This step is necessary to properly escape the ':' for the subsequent docker commands\n\n```sh\nexport DOCKER_IMAGE=$ECR_URL\u002F$IMAGE_NAME\\:latest\n```\n\nBuild the docker image\n\n```sh\ndocker build -t $DOCKER_IMAGE . \n```\n\nExpected output\n```sh\n[+] Building 0.5s (7\u002F7) FINISHED\n => [internal] load build definition from Dockerfile                                                             0.0s\n => => transferring dockerfile: 37B                                                                              0.0s\n => [internal] load .dockerignore                                                                                0.0s\n => => transferring context: 2B                                                                                  0.0s\n => [internal] load metadata for public.ecr.aws\u002Flambda\u002Fgo:1                                                      0.3s\n => [internal] load build context                                                                                0.1s\n => => transferring context: 13.18MB                                                                             0.1s\n => [1\u002F2] FROM public.ecr.aws\u002Flambda\u002Fgo:1@sha256:ea8389f1a5e7e9d29c4d65008da143985bef131cf901db63ab57e4124f7f66  0.0s\n => CACHED [2\u002F2] COPY main \u002Fvar\u002Ftask                                                                             0.0s\n => exporting to image                                                                                           0.0s\n => => exporting layers                                                                                          0.0s\n => => writing image sha256:0f3ea389fa4f3761f25b2b666a8f49b458e825f1180b9c2181ecadd55fd2cc9a                     0.0s\n => => naming to 111122223333.dkr.ecr.us-east-1.amazonaws.com\u002Flambda-test:latest\n```\n\nUpload the docker image to ECR\n\n```sh\ndocker push $DOCKER_IMAGE\n```\n\nExpected output\n\n```sh\nThe push refers to repository [111122223333.dkr.ecr.us-east-1.amazonaws.com\u002Flambda-test]\n8ce4b9b80622: Pushed\n02c5912fad21: Pushed\n2d244e0816c6: Pushed\n2b58bd9b1feb: Pushed\nd79a81893db4: Pushed\n2ad9f6dfcb67: Pushed\nlatest: digest: sha256:86bb30cbf14d9ac538946cdd9565f09b7a4a0b9846e28a73cd27116280c0a58e size: 1579\n```\n\n## Conclusion\n\nIn this module, we covered how to build a Docker image, create an ECR repo, and upload an image to it. In the next module, we will learn how to deploy the serverless application.",[13],"content\u002Fcontributors\u002Fdavid-boyne.json","LIST","Deploy a Serverless Application using Crossplane on EKS","\u002Fcontent\u002Fguides\u002Fserverless-crossplane-on-eks\u002Fdocker-image","2 min",[19,32],{"title":20,"content":21},"Introduction",[22],{"title":23,"order":24,"learningGoals":25,"time":17,"path":29,"id":30,"link":31},"Overview",1,[26,27,28],"Create a Docker image and push it to ECR.","Set Crossplane underlying Compositions and XRDs, and use Claims.","Validate results with basic commands using kubectl and the AWS CLI.","introduction","introduction.md","\u002Fcontent\u002Fguides\u002Fserverless-crossplane-on-eks\u002Fintroduction",{"title":33,"content":34},"Modules",[35,39,48,57],{"title":6,"order":7,"learningGoals":36,"time":17,"path":37,"id":38,"link":16},[9,10],"docker-image","docker-image.md",{"title":40,"order":7,"learningGoals":41,"time":44,"path":45,"id":46,"link":47},"2. Deploy the serverless application",[42,43],"Deploying Crossplane XRDs and Compositions","Deploying a Claim to create serverless application","3 min","deployment","deployment.md","\u002Fcontent\u002Fguides\u002Fserverless-crossplane-on-eks\u002Fdeployment",{"title":49,"order":7,"learningGoals":50,"time":53,"path":54,"id":55,"link":56},"3. Test",[51,52],"Pushing messages to SQS using the AWS CLI.","Exploring the AWS SQS, Lambda, and S3 consoles.","1 min","testing","testing.md","\u002Fcontent\u002Fguides\u002Fserverless-crossplane-on-eks\u002Ftesting",{"title":58,"order":7,"learningGoals":59,"time":53,"path":62,"id":63,"link":64},"4. Clean up resources",[60,61],"How to remove Crossplane resources","How to destroy EKS cluster if created using the GitHub repository.","cleanup","cleanup.md","\u002Fcontent\u002Fguides\u002Fserverless-crossplane-on-eks\u002Fcleanup",1792578866301]