Untitled
unknown
plain_text
4 years ago
1.4 kB
6
Indexable
# Table exercize ## Template.yml AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Serverless Stack Resources: hello: Type: AWS::Serverless::Function Properties: Runtime: python3.9 Handler: lambda.hello CodeUri: s3://instruqt-martijn2/0eb1105bb30ddc068e9504ae7094c613 Environment: Variables: LINKS_TABLE: Ref: linkTable Events: Hello: Type: Api Properties: Path: / Method: get linkTable: Type: AWS::Serverless::SimpleTable Properties: TableName: linkstable PrimaryKey: Name: id Type: String Outputs: url: Value: Fn::Sub: https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod table: Value: Ref: linkTable ## Src/Lambda.py import boto3 import json import os # some import maybe? def hello(event, context): # replace world below for the env var my_env_var = os.environ['LINKS_TABLE'] body = {"hello": my_env_var} return { "statusCode": 200, "body": json.dumps(body) } ## package # aws cloudformation package --template-file template.yml --s3-bucket instruqt-martijn2 --output-template-file packaged-template.yml ## deploy # aws cloudformation deploy --template-file /root/packaged-template.yml --stack-name instruqt --capabilities CAPABILITY_IAM
Editor is loading...