From 6b3befb73382fef86cea0ce8e1fb889fb25bb0db Mon Sep 17 00:00:00 2001 From: Goumain Date: Sat, 19 Aug 2023 15:46:19 +0100 Subject: [PATCH] added all files --- lambda-ecr/README.md | 62 +++++++++++++++++++++++++++++++++ lambda-ecr/example-pattern.json | 53 ++++++++++++++++++++++++++++ lambda-ecr/template.yaml | 17 +++++++++ 3 files changed, 132 insertions(+) create mode 100644 lambda-ecr/README.md create mode 100644 lambda-ecr/example-pattern.json create mode 100644 lambda-ecr/template.yaml diff --git a/lambda-ecr/README.md b/lambda-ecr/README.md new file mode 100644 index 000000000..44cb2b10c --- /dev/null +++ b/lambda-ecr/README.md @@ -0,0 +1,62 @@ +# AWS Lambda with a container image + +This pattern will create a Lambda function with an ECR image. You will need to have the ECR image already created in your account. + +Learn more about this pattern at Serverless Land Patterns: << Add the live URL here >> + +Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. + +## Requirements + +* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. +* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured +* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed + +## Deployment Instructions + +1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: + ``` + git clone https://github.com/aws-samples/serverless-patterns + ``` +1. Change directory to the pattern directory: + ``` + cd _patterns-model + ``` +1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file: + ``` + sam deploy --guided + ``` +1. During the prompts: + * Enter a stack name + * Enter the EcrUri in the parameters + * Allow SAM CLI to create IAM roles with the required permissions. + + Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults. + +1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing. + +## How it works + +This patterns deployes a lambda function running with a container image from an ECR repository in your account. You will need to have the ECR image already created in your account and enter its URI in the parameter of the template. + +## Testing + +While deploying the template, make sure you enter the EcrUri in the parameters of an existing ECR image in your account. + +Once the function is deployed, you can click on the resource to go to the Lambda console and test the function there. + +## Cleanup + +1. Delete the stack + ```bash + aws cloudformation delete-stack --stack-name STACK_NAME + ``` +1. Confirm the stack has been deleted + ```bash + aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus" + ``` +---- +Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + +SPDX-License-Identifier: MIT-0 \ No newline at end of file diff --git a/lambda-ecr/example-pattern.json b/lambda-ecr/example-pattern.json new file mode 100644 index 000000000..a0627ca87 --- /dev/null +++ b/lambda-ecr/example-pattern.json @@ -0,0 +1,53 @@ +{ + "title": "Lambda function with ECR Image", + "description": "Create a Lambda function with a container image", + "language": "YAML", + "level": "200", + "framework": "SAM", + "introBox": { + "headline": "How it works", + "text": [ + "This template will create a lambda function running with an ECR container image.", + "You will need to already have the ECR image created in your account" + ] + }, + "gitHub": { + "template": { + "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/lambda-ecr", + "templateURL": "serverless-patterns/lambda-ecr", + "projectFolder": "lambda-ecr", + "templateFile": "lambda-ecr/template.yml" + } + }, + "resources": { + "bullets": [ + { + "text": "Working with Lambda container images", + "link": "https://docs.aws.amazon.com/lambda/latest/dg/images-create.html" + } + ] + }, + "deploy": { + "text": [ + "sam deploy" + ] + }, + "testing": { + "text": [ + "Enter the Image URI in the parameters of the template. Once deployed, you can invoke the Lambda function." + ] + }, + "cleanup": { + "text": [ + "Delete the stack: sam delete." + ] + }, + "authors": [ + { + "name": "Alice Goumain", + "image": "https://media.licdn.com/dms/image/C4E03AQFu1xnGt76xzg/profile-displayphoto-shrink_800_800/0/1662636936708?e=1686182400&v=beta&t=9RZra4EtrGWhcWVYZZtP_W9yrUR_XZ9ued70sTnkCgg", + "bio": "Cloud Support Engineer in Serverless @ AWS", + "linkedin": "https://www.linkedin.com/in/alice-goumain/" + } + ] +} diff --git a/lambda-ecr/template.yaml b/lambda-ecr/template.yaml new file mode 100644 index 000000000..dc49528f4 --- /dev/null +++ b/lambda-ecr/template.yaml @@ -0,0 +1,17 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: This templates creates a Lambda function running with an ECR Image. The ECR image needs to be entered in the parameters + +Parameters: + EcrUri: + Type: String + Description : The Image Uri of the container image, for instance "112233445566.dkr.ecr.eu-west-1.amazonaws.com/hello-world:latest" + +Resources: + LambdaEcr: + Type: AWS::Serverless::Function + Properties: + PackageType: Image + ImageUri: !Ref EcrUri + MemorySize: 256 + Timeout: 30