Skip to content

Instantly share code, notes, and snippets.

@Arunmainthan
Last active December 15, 2019 11:05
Show Gist options
  • Save Arunmainthan/f45fdc1381535a0e15d2cd8c61620742 to your computer and use it in GitHub Desktop.
Save Arunmainthan/f45fdc1381535a0e15d2cd8c61620742 to your computer and use it in GitHub Desktop.
serverless.yml IAM permissions
import json
import boto3
import json
import boto3
def hello(event, context):
# TODO implement
resource='s3'
s3=boto3.resource(resource)
s3Bucket='bucketname'
bucketKey='customer.json'
obj=s3.Object(s3Bucket,bucketKey)
body=obj.get()['Body'].read()
customer={}
customer=json.loads(body)
value={}
# customerCode is the parameter defined in your serverless.yml
customerCode = event['pathParameters']['customerCode']
return {
'statusCode': 200,
'body': json.dumps(customer[customerCode]),
'headers': {
"content-type": "application/json"
}
}
service: customer-function
provider:
name: aws
runtime: python3.8
region: eu-west-1
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:ListBucket"
Resource: "arn:aws:s3:::bucketname"
- Effect: "Allow"
Action:
- "s3:PutObject"
- "s3:GetObject"
- "s3:DeleteObject"
Resource: "arn:aws:s3:::bucketname/*"
functions:
hello:
handler: handler.hello
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
events:
- http:
path: customer_1/cust-details/{customerCode}
method: get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment