gustavomf-cit / localstack_examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aws stuff

Deploy lambda

awslocal --endpoint-url=http://localhost:4574 \
                                            lambda \
                                            create-function --function-name=lambda_queue \
                                            --runtime=python3.5 \
                                            --role=lambda_policy \
                                            --handler=app.lambda_handler \
                                            --zip-file fileb://lambda.zip
{
    "FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:lambda_queue",
    "FunctionName": "lambda_queue",
    "TracingConfig": {},
    "Environment": {
        "Variables": {},
        "Error": {}
    },
    "Handler": "app.lambda_handler",
    "VpcConfig": {
        "SubnetIds": [
            null
        ],
        "SecurityGroupIds": [
            null
        ]
    },
    "Role": "lambda_policy",
    "Runtime": "python3.5"
}

Generate modules

python3 -m pip install -r lambda/requirements.txt -t lambda/

Create apigateway

awslocal apigateway create-rest-api --name 'Lambda rest API'
{
    "createdDate": 1520431102,
    "id": "06A-Z3A-ZA-Z3695",
    "name": "Lambda rest API"
}

Get id above to check the resources

awslocal apigateway get-resources --rest-api-id 06A-Z3A-ZA-Z3695
{
    "items": [
        {
            "resourceMethods": {
                "GET": {}
            },
            "path": "/",
            "id": "44539A-Z2568"
        }
    ]
}

add lambda to apigateway

awslocal lambda list-functions
{
    "Functions": [
        {
            "FunctionName": "hello_world",
            "CodeSize": 50,
            "Handler": "app.lambda_handler",
            "Version": "$LATEST",
            "Environment": {},
            "FunctionArn": "arn:aws:lambda:us-east-1:000000000000:function:hello_world",
            "Runtime": "python3.5"
        }
    ]
}

awslocal apigateway put-integration \
            --rest-api-id 06A-Z3A-ZA-Z3695 \
            --resource-id 44539A-Z2568 \
            --http-method GET \
            --type AWS \
            --integration-http-method GET \
            --uri aws:lambda:us-east-1:000000000000:function:hello_world

awslocal apigateway create-deployment \
                --rest-api-id 06A-Z3A-ZA-Z3695 \
                --stage-name prod

Create s3 bucket

awslocal s3 mb s3://test

Create stack using cloudformation

awslocal cloudformation create-stack --template-body file://cloudformation_templates/template.json --stack-name sqs
awslocal lambda invoke \
            --invocation-type Event \
            --function-name hello_world \
            outputfile.txt

About

License:Apache License 2.0


Languages

Language:Python 89.1%Language:Shell 10.9%