Example IAM Role + Lambda
This will fail, you'll need to fix it somehow!
export \
AWS_PROFILE=nbos-sandbox \
AWS_REGION=us-west-2 \
STACK_NAME=sample-lambda-${RANDOM}
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudformation deploy \
--stack-name ${STACK_NAME} \
--template-file cloudformation.yaml \
--capabilities CAPABILITY_IAM
FUNCTION_NAME=$(aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudformation describe-stacks \
--stack-name ${STACK_NAME} \
--output text \
--query "Stacks[0].Outputs[?OutputKey == 'ExampleFunction']. OutputValue")
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} lambda invoke \
--payload '{ "foo": "bar" }' \
--function-name ${FUNCTION_NAME} \
_out.json
BUCKET_NAME=$(aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudformation describe-stacks \
--stack-name ${STACK_NAME} \
--output text \
--query "Stacks[0].Outputs[?OutputKey == 'ExampleBucket']. OutputValue")
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} s3 rb s3://${BUCKET_NAME} --force
aws --profile ${AWS_PROFILE} --region ${AWS_REGION} cloudformation delete-stack \
--stack-name ${STACK_NAME}
example ~/.aws/config
[profile lambda]
role_arn = arn:aws:iam::631042910881:role/example-lambda/example-lambda-ExampleLambdaExecutionRole-555W089C0550
source_profile = nbos-sandbox
test it
AWS_PROFILE=lambda aws whoami
... or
AWS_PROFILE=lambda aws s3 cp cloudformation.yaml s3://sample-lambda-12156-examplebucket-uevbfk47h3on/
JavaScript SDK default credential provider doesn't use source_profile
aws/aws-sdk-js#1064
instead -- you can use this (use this only locally)
import * as AWS from "aws-sdk"
AWS.config.credentials = new AWS.ChainableTemporaryCredentials({
params: {
RoleArn: 'arn:aws:iam::453719517077:role/ris-dev-2-export-service-StartQueryFunctionRole-11YF9WSUGVA2H',
RoleSessionName: "temp",
}
})