diff --git a/bin/aws_sam_cli_install.sh b/bin/aws_sam_cli_install.sh new file mode 100755 index 0000000..2af2c85 --- /dev/null +++ b/bin/aws_sam_cli_install.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +cd /workspace +curl -L "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip" -o "samcli.zip" +unzip samcli.zip -d sam-installation +sudo ./sam-installation/install +cd $THEIA_WORKSPACE_ROOT \ No newline at end of file diff --git a/lambda/inline/.aws-sam/build.toml b/lambda/inline/.aws-sam/build.toml new file mode 100644 index 0000000..678bce4 --- /dev/null +++ b/lambda/inline/.aws-sam/build.toml @@ -0,0 +1,5 @@ +# This file is auto generated by SAM CLI build command + +[function_build_definitions] + +[layer_build_definitions] diff --git a/lambda/inline/.aws-sam/build/template.yaml b/lambda/inline/.aws-sam/build/template.yaml new file mode 100644 index 0000000..c5714fb --- /dev/null +++ b/lambda/inline/.aws-sam/build/template.yaml @@ -0,0 +1,12 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Resources: + InlineLambda: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: python3.12 + PackageType: Zip + InlineCode: "def handler(event, context):\n message = 'Hello {} {}!'.format(event['first_name'],\ + \ event['last_name']) \n print(\"Log this for me\")\n return { \n \ + \ 'message' : message\n }" diff --git a/lambda/inline/Readme.md b/lambda/inline/Readme.md new file mode 100644 index 0000000..5aa2a92 --- /dev/null +++ b/lambda/inline/Readme.md @@ -0,0 +1,11 @@ +# Install SAM CLI + +```sh +./bin/aws_sam_cli_install.sh +``` + +# Install CFN Lint + +```sh +brew install cfn-lint +``` \ No newline at end of file diff --git a/lambda/inline/bin/build b/lambda/inline/bin/build new file mode 100755 index 0000000..8de0047 --- /dev/null +++ b/lambda/inline/bin/build @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e + +# we need the absolute path of samconfig.toml +# because relative path was giving us trouble +root_path=$(realpath .) +template_path="${root_path}/template.yml" + +# sam build +# =================== +# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-building.html +# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html +# ------------------- +# This will prepare the artifact to be uploaded to S3 by generating: +# .aws-sam/build/template.yml +echo "== SAM build..." +echo "using template: ${template_path}" +sam build \ + --template-file "${template_path}" \ No newline at end of file diff --git a/lambda/inline/bin/deploy b/lambda/inline/bin/deploy new file mode 100755 index 0000000..d385fb5 --- /dev/null +++ b/lambda/inline/bin/deploy @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -e + +# we need the absolute path because relative path was giving us trouble +root_path=$(realpath .) +#config_path="$(realpath ..)/python.toml" + +#if [ ! -f "$config_path" ]; then +# echo "$config_path does not exist." +# exit 1 +#fi + +# sam deploy +# =================== +# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html +# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html +# ------------------- +echo "== SAM deploy..." +#echo "loading configuration: $config_path" + +sam deploy \ + --template-file "./.aws-sam/build/template.yaml" \ + --stack-name "inline-lamba-py" \ + --capabilities "CAPABILITY_IAM" + #--config-file "$config_path" \ \ No newline at end of file diff --git a/lambda/inline/bin/lint b/lambda/inline/bin/lint new file mode 100755 index 0000000..0c3b565 --- /dev/null +++ b/lambda/inline/bin/lint @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e + +# we need the absolute path because relative path was giving us trouble +root_path=$(realpath .) + +# cfn-lint +# ------------------- +# This will check our cloudformation template to ensure its valid format +echo "== CFN linting..." +cfn-lint "${root_path}/template.yml" \ No newline at end of file diff --git a/lambda/inline/function/function.py b/lambda/inline/function/function.py new file mode 100644 index 0000000..bd629a4 --- /dev/null +++ b/lambda/inline/function/function.py @@ -0,0 +1,5 @@ +def handle(event, context): + message = 'Hello {} {}!'.format(event['first_name'], event['last_name']) + return { + 'message' : message + } \ No newline at end of file diff --git a/lambda/inline/template.yml b/lambda/inline/template.yml new file mode 100644 index 0000000..743a338 --- /dev/null +++ b/lambda/inline/template.yml @@ -0,0 +1,17 @@ +AWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Resources: + # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html + InlineLambda: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: python3.12 + PackageType: Zip + InlineCode: | + def handler(event, context): + message = 'Hello {} {}!'.format(event['first_name'], event['last_name']) + print("Log this for me") + return { + 'message' : message + } \ No newline at end of file